c# - How can I filter rows where the first character of a column is in a range with EF and SQL Server? -


i have following table:

create table [dbo].[phrase] (     [phraseid]      uniqueidentifier default (newid()) not null,         [english]       nvarchar (250)   not null ) 

is there way using entity framework can pick rows first character of [english] column less "k". example either "a", "b", "c" ... "j" etc

something this:

query = query.where(w =>   w.english.startswith("k"); 

but range of characters , not "k"

you can filter after fetching records db. can following:

var result = query.tolist(); 

and filter follows:

result = result.where(w => convert.tochar(w.english.substring(0,1).tolower()) < 'k'); 

in sql server, following query work:

select * table substring(english, 1, 1) < 'k' 

for range of characters, query be:

select * table substring(english, 1, 1) betweeb 'a' , 'j' 

the above fetch records on condition english column's first character should in between of a , j. please note a , j inclusive in case.

for specific characters, query be:

 select * table substring(english, 1, 1) in ('a', 'd', 'f') 

the above return records english column starts a, d, f. negate can use not in ('a', 'd', 'f')

i suggest write procedure above query , call using entity framework. approach faster.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -