Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda Expression for "not in"?

Tags:

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))
like image 341
angel Avatar asked Mar 22 '13 16:03

angel


1 Answers

Selected details collection items which ids are not in codesarray:

detailcollection.Where (x=> !codesarray.Contains(x.ope_idsku))
like image 66
Zbigniew Avatar answered Sep 24 '22 02:09

Zbigniew