Export (0) Print
Expand All

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

Use the Intersect operator to return the set intersection of two sequences.

This example uses Intersect to return a sequence of all countries in which both Customers and Employees live.


var infoQuery =
    (from cust in db.Customers
    select cust.Country)
    .Intersect
        (from emp in db.Employees
        select emp.Country)
;


In LINQ to SQL, the Intersect operation is well defined only on sets. The semantics for multisets is undefined.

Show:
© 2014 Microsoft