How can I do something like this:
customers.where(c=>c.Name **like** "john");
I know this isn't possible but I was wondering how can I have something similar.
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.
Advertisements. The term 'Lambda expression' has derived its name from 'lambda' calculus which in turn is a mathematical notation applied for defining functions. Lambda expressions as a LINQ equation's executable part translate logic in a way at run time so it can pass on to the data source conveniently.
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.
There is no performance difference between LINQ queries and Lambda expressions.
customers.Where(c => c.Name.Contains("john"));
If you are targeting LINQ to SQL, use SqlMethods.Like:
customers.Where(c => SqlMethods.Like(c.Name, "%john%"));
Explanation:
The compiler will generate an expression tree from the statement above. Since LIKE
is a SQL specific construct and not common to all LINQ Query providers, the SqlMethods
class and its members are used as a "hint" for the expression compiler (compiles expression trees to SQL) to emit a LIKE
statement.
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