What is equivalent to clause between, for comparasion strings in LINQ or lambda expression of?

asp.net-mvc-3 c# entity-framework linq razor

Question

How do I filter a query interval of two string using LINQ or Lambda Expression.

example:

SELECT * FROM dbo.Country WHERE Name BETWEEN "Argentina" AND "Jamaica";
1
15
9/18/2012 12:18:18 PM

Accepted Answer

Have you tried:

yourDataContext.Country.Where(c => c.Name >= "Argentina" && c.Name <= "Jamaica");
11
9/18/2012 12:13:53 PM

Popular Answer

perpetrators >= and <= are not for strings. they will throw compile time error to you. you can use CompareTo for this as shown below

x.Name.CompareTo(Start) >= 0 && x.Name.CompareTo(End) <= 0


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow