Exception syntax syntax with Linq, VB
I would like to do set subtraction based on criteria. The pseudo query will look like this:
select table1.columnn1
,table1.column2
from table1, table2
where (table1.column1.value1 not in table2.column1
and
table1.column2.value2 not in table2.column2)
I can do it roughly here:
dim list = From tbl1 In table1 Where tt.column1 ...
And from there I don't know what to do.
+1
source to share
1 answer
Have a look at the standard query operator Except
in LINQ. This creates a predetermined difference in the two sequences.
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.except.aspx
You can also use the operator Contains
to achieve what you want according to the example below:
dim table2Col1 = from t in table2 select t.column1
dim table2Col2 = from t in table2 select t.column2
dim results = _
from t in table1 _
where not table2Col1.Contains(t.column1) _
and not table2Col2.Contains(t.column2) _
select new with { .column1=t.column1, .column2=t.column2 }
+2
source to share