【问题标题】:Exclusionary Set Syntax with Linq, VBLinq,VB 的排他集语法
【发布时间】:2010-10-24 00:35:52
【问题描述】:

我想根据标准对集合进行减法。伪查询如下所示:

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

从那里我不知道该怎么办。

【问题讨论】:

    标签: vb.net linq dataset set


    【解决方案1】:

    查看 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 }
    

    【讨论】:

    • 非常感谢,您确实将我引向了正确的方向。
    猜你喜欢
    • 2022-06-20
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多