views:

44

answers:

3

I have "Contains" method but I need a "Not Contains" method. Any suggestions?

var ResultsOfMPD = (from m in engMpdMultiSelect
                    where engMpdMultiItems.Select(o => o.ENG_MPD_MYTECHNIC_TASK_NO).
                    Contains(m.ENG_MPD_MYTECHNIC_TASK_NO)
                    select m);

is there any method like that?

var ResultsOfMPD = (from m in engMpdMultiSelect
                    where engMpdMultiItems.Select(o => o.ENG_MPD_MYTECHNIC_TASK_NO).
                    NOTContains(m.ENG_MPD_MYTECHNIC_TASK_NO)
                    select m);
+1  A: 

Use the ! operator, like this:

var ResultsOfMPD = from m in engMpdMultiSelect
                   where !engMpdMultiItems.Select(o => o.ENG_MPD_MYTECHNIC_TASK_NO).
                   Contains(m.ENG_MPD_MYTECHNIC_TASK_NO)
                   select m;

By the way, you don't need the Select() call.
Instead, you can write

var ResultsOfMPD = from m in engMpdMultiSelect
                   where !engMpdMultiItems.Any(o => o.ENG_MPD_MYTECHNIC_TASK_NO == m.ENG_MPD_MYTECHNIC_TASK_NO)
                   select m;

Or, equivalently,

var ResultsOfMPD = from m in engMpdMultiSelect
                   where engMpdMultiItems.All(o => o.ENG_MPD_MYTECHNIC_TASK_NO != m.ENG_MPD_MYTECHNIC_TASK_NO)
                   select m;
SLaks
how can i use? !contains(. . . .
Phsika
If Foo() returns boolean, !Foo() returns the opposite, therefore if engMpdMultiItems.Select().Contains() returns boolean, !engMpdMultiItems.Select().Contains() returns the opposite.
Tergiver
A: 
var ResultsOfMPD = from m in engMpdMultiSelect
                   where engMpdMultiItems.All(x => x.ENG_MPD_MYTECHNIC_TASK_NO != m.ENG_MPD_MYTECHNIC_TASK_NO)
                   select m;
LukeH
A: 

How about the Except method?

FYI - In set theory this is called a Relative Complement. That is, given two sets A and B, the set of all elements which are in B but not in A is referred to as the relative complement of set A with respect to set B. But not contains or except works too.

rtalbot