返回两个序列之间的集合差异

使用 Except 运算符返回两个序列之间的集差。

示例:

此示例使用 Except 返回有 Customers 居住但无 Employees 居住的所有国家/地区的序列。

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

在 LINQ to SQL 中,Except 操作仅在集上定义明确。 多集的语义未定义。

另请参阅