2009-05-05 30 views
1

我想根據標準進行減法。僞查詢看起來像:排除與Linq,VB設置語法

select table1.columnn1 
     ,table1.column2 
    from table1, table2 
where (table1.column1.value1 not in table2.column1 
     and 
     table1.column2.value2 not in table2.column2) 

我可以把它約在這裏:

dim list = From tbl1 In table1 Where tt.column1 ... 

從那裏,我不知道該怎麼辦。

回答

2

看看LINQ中的Except標準查詢運算符。這產生兩個序列的設定差異。

http://msdn.microsoft.com/en-us/library/system.linq.enumerable.except.aspx

您也可以使用Contains運營商實現你想要的,如下面的例子:

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 } 
+0

謝謝了,你肯定把我領到了正確的方向。 – Daniel 2009-05-06 12:41:32