Defining a Left Join with LINQ Queries (
Page 1 of 4 )
LINQ supports the notion of equijoins and non-equijoins. Equijoin is contrived using the join on equals clause
in a LINQ query. A non-equijoin is everything else, typical devised
with a where predicate performing some test on elements from more than
one sequence. And equijoin is fundamentally an inner join. An inner
join correlates one element in one sequence with an element in another
sequence. Only elements from each sequence that are correlated with an
element in the other sequence is returned as a resultset of the LINQ
query.
Introduction
LINQ supports the notion of equijoins and non-equijoins. Equijoin is contrived using the join on equals clause in a LINQ query. A non-equijoin is everything else, typical devised with a where predicate performing some test on elements from more than one sequence. And equijoin is fundamentally an inner join. An inner join correlates one element in one sequence with an element in another sequence. Only elements from each sequence that are correlated with an element in the other sequence is returned as a resultset of the LINQ query.
A left join is a join is a join that returns everything in the left (or first) sequence and only those elements in the right (or second) sequence that is correlated to elements in the left sequence. We can also refer to a left join as all master elements and only those elements in the detail sequence that are related to something in the master sequence. (Figure 1 depicts the difference in the result sets between inner and left joins.
Figure 1: A inner join is the intersection of elements in the two sets, usually established by an indexed key; the left join is everything in the master set and the intersecting elements in the right set.

There is no native join keywords that express a left join. A left join can be contrived using the into keyword that is the basis of a group join. This article demonstrates how to implement left joins with LINQ. (For more on joins checkout my upcoming book LINQ Unleashed: for C# from Sams, available July 2008.)