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";
Language Integrated Query (LINQ) is feature of Visual Studio that gives you the capabilities yo query on the language syntax of C#, so you will get SQL kind of queries. And Lambda expression is an anonymous function and is more of a like delegate type.
So performance-wise, there's no difference whatsoever between the two. Which one you should use is mostly personal preference, many people prefer lambda expressions because they're shorter and more concise, but personally I prefer the query syntax having worked extensively with SQL.
A lambda expression is a convenient way of defining an anonymous (unnamed) function that can be passed around as a variable or as a parameter to a method call. Many LINQ methods take a function (called a delegate) as a parameter.
The => operator can be used in two ways in C#: As the lambda operator in a lambda expression, it separates the input variables from the lambda body. In an expression body definition, it separates a member name from the member implementation.
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
Have you tried:
yourDataContext.Country.Where(c => c.Name >= "Argentina" && c.Name <= "Jamaica");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With