Does anyone any idea how can we use where not in() statement with lambda?
this is where id in() statement
public List<abc> GetList(List<string> ID)
{
return db.abcs.Where(a => ID.Contains(a.id)).ToList<abc>();
}
I'd like to find how cloud it be opposite. "where id not in..."
Which is NOT true about lambda statements? A statement lambda cannot return a value.
In lambda expressions, the lambda operator => separates the input parameters on the left side from the lambda body on the right side.
the operator => has nothing to do with linq - it's a lambda expression. It's used to create anonymous functions, so you don't need to create a full function for every small thing.
Using if-else in lambda function Here, if block will be returned when the condition is true, and else block will be returned when the condition is false. Here, the lambda function will return statement1 when if the condition is true and return statement2 when if the condition is false.
Simply add a not (!
) operator:
// Not In
return db.abcs.Where(a => !ID.Contains(a.id)).ToList();
Why not ?
return db.abcs.Where(a => ! ID.Contains(a.id)).ToList<abc>();
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