Lambda Expression for "not in"?

angel picture angel · Mar 22, 2013 · Viewed 31k times · Source

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))

Answer

Zbigniew picture Zbigniew · Mar 22, 2013

Selected details collection items which ids are not in codesarray:

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