9

Possible Duplicate:
LINQ Between Operator

Dear All,
Hi,
I need to write this query in LINQ C#. can anyone help me?

Select *  
From Mytable  
where MyText BETWEEN 'john' AND 'Pear'    
Community
  • 1
  • 1
LIX
  • 1,489
  • 5
  • 22
  • 33

2 Answers2

8

I believe this query should work:

var results = yourTable.Where(x => x.Text.CompareTo("john") > 0 && 
                                   x.Text.CompareTo("Pear") < 0);

This assumes that you want to compare the text in each row of the table, and not some pre-dfined string.

jjnguy
  • 136,852
  • 53
  • 295
  • 323
3

Here is how you can do it with ObjectQuery

MytableSet.Where("it.Name between @start and @end", new ObjectParameter("start", "john"), new ObjectParameter("end", "Pear"))

EDIT:

Forget to mention that this statement is specific to Entity Framework not LINQ2SQL.

Oleg I.
  • 803
  • 5
  • 12