Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where not in () statement with lambda

Tags:

c#

lambda

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..."

like image 518
serhads Avatar asked Feb 09 '12 15:02

serhads


People also ask

Which sentence about lambda statement is not true?

Which is NOT true about lambda statements? A statement lambda cannot return a value.

What does => mean in lambda?

In lambda expressions, the lambda operator => separates the input parameters on the left side from the lambda body on the right side.

What does => mean in Linq?

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.

How do you write lambda with if-else?

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.


2 Answers

Simply add a not (!) operator:

// Not In
return db.abcs.Where(a => !ID.Contains(a.id)).ToList();
like image 195
Phil Klein Avatar answered Sep 23 '22 10:09

Phil Klein


Why not ?

return db.abcs.Where(a => ! ID.Contains(a.id)).ToList<abc>();
like image 25
Mithrandir Avatar answered Sep 25 '22 10:09

Mithrandir