angel
angel

Reputation: 4632

Lambda Expression for "not in"?

I have a detailcollection collection in which every detail has

code, price, name

And a string with some codes

string codes = "1,2,3";

I know I can get an array using string.Split()

string[] codesarray = codes.Split(',');

But how can I get products not in codes?

// the idea I have, but I would not like to have a loop
for (int i = 0; i < codesarray.Length; i++)
{
    detailcollection.Where(x => x.ope_idsku == codesarray[i])
}

I would like something like:

detailcollection.Where(x => x.ope_idsku not in (codesarray))

Upvotes: 21

Views: 41525

Answers (1)

Zbigniew
Zbigniew

Reputation: 27594

Selected details collection items which ids are not in codesarray:

detailcollection.Where (x=> !codesarray.Contains(x.ope_idsku))

Upvotes: 43

Related Questions