I'm looking for to build the Lambda expression like the below
IQueryable<Object> queryEntity = _db.Projects.Where(Project=>Project.Id.IN(1,2,3,4));
I don't find any IN
operator in Lambda expression.
Anybody have suggestions?
In lambda expressions, the lambda operator => separates the input parameters on the left side from the lambda body on the right side. Func<string> greet = () => "Hello, World!"; Console. WriteLine(greet()); For more information, see Lambda expressions.
The lambda operator => divides a lambda expression into two parts. The left side is the input parameter and the right side is the lambda body.
Lambda expressions are like anonymous methods but with much more flexibility. When using a lambda expression, you don't need to specify the type of the input. Hence, a lambda expression provides a shorter and cleaner way of representing anonymous methods.
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.
Use IEnumerable.Contains for this.
var idList = new[] { 1, 2, 3, 4 }; IQueryable<Object> queryEntity = _db.Projects.Where(Project => idList.Contains(Project.Id));
You could construct the idList
inline of course.
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