Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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";
like image 384
Mateus Benetti Avatar asked Sep 18 '12 12:09

Mateus Benetti


People also ask

What is difference between LINQ and lambda expression?

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.

Can you use lambda expression instead of LINQ query?

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.

What are the lambda expressions and LINQ?

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.

What does => mean in LINQ?

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.


2 Answers

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
like image 165
Aqdas Avatar answered Oct 23 '22 05:10

Aqdas


Have you tried:

yourDataContext.Country.Where(c => c.Name >= "Argentina" && c.Name <= "Jamaica");
like image 35
Bardo Avatar answered Oct 23 '22 07:10

Bardo