Ziff-Davis Enterprise 
DevSource: Microsoft Developer Resource
Add OnsArchitectureLanguagesTechniquesUsing VSForums
 
Home arrow Languages arrow Defining a Left Join with LINQ Queries
Defining a Left Join with LINQ Queries
By Paul Kimmel

Rate This Article:
Add This Article To:
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

ADVERTISEMENT

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



 
 
>>> More Languages Articles          >>> More By Paul Kimmel
 



DevSource video
Devsource Video Series
Manipulating Society through Technology
Jeremy Bailenson, Director of the Virtual Human Interaction Lab at Stanford University, talks about virtual reality, avatars, Moore's law, how real world behaviors influence online reality, and societal manipulation through technology!
>> Play video
>> Read article
>> See all videos
DevLife Blog

Julia explores the Robotics Studio! (It's for more than you think.)

MSDev Blog

Messages for Bill Gates!

Make it Work
.NET makes runtime type checking a breeze. See what Peter has to say about it in this week's tips!
News
Microsoft Counts on App Support for Vista
Microsoft has taken pains to demonstrate that Windows Vista will have ample application support.
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.