Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

How to: Return the Set Union of Two Sequences (LINQ to SQL)

Use the Union operator to return the set union of two sequences.

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)
        (from emp in db.Employees
        select emp.Country)

In LINQ 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).

© 2015 Microsoft