傳回兩個序列的集合聯集Return the Set Union of Two Sequences

使用 Union 運算子傳回兩個序列的集合聯集。Use the Union operator to return the set union of two sequences.

範例Example

這個範例會使用 Union 傳回 CustomersEmployees 所在的所有國家/地區序列。This example uses Union to return a sequence of all countries in which there are either Customers or Employees.

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

LINQ to SQLLINQ to SQL,則Union運算子指 (semantics) 的未排序串連 (有效的結果 UNION ALL SQL 中的子句)。In LINQ to SQLLINQ to SQL, the Union operator is defined for multisets as the unordered concatenation of the multisets (effectively the result of the UNION ALL clause in SQL).

如需詳細資訊和範例,請參閱Queryable.UnionFor more info and examples, see Queryable.Union.

另請參閱See also