如何:返回两个序列的交集 (LINQ to SQL)

更新:November 2007

使用 Intersect 运算符可返回两个序列的交集。

示例

此示例使用 Intersect 返回既有 Customers 居住又有 Employees 居住的所有国家/地区的序列。

Dim infoQuery = _
    (From cust In db.Customers _
    Select cust.Country) _
    .Intersect _
        (From emp In db.Employees _
        Select emp.Country)
var infoQuery =
    (from cust in db.Customers
    select cust.Country)
    .Intersect
        (from emp in db.Employees
        select emp.Country)
;

在 LINQ to SQL 中,Intersect 运算仅对集合而言是定义完善的。针对多重集的语义尚未定义。

请参见

参考

标准查询运算符转换 (LINQ to SQL)

其他资源

查询示例 (LINQ to SQL)