What is equivalent to clause between, for comparas

2019-04-19 02:00发布

问题:

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:

Have you tried:

yourDataContext.Country.Where(c => c.Name >= "Argentina" && c.Name <= "Jamaica");


回答2:

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