Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

Join Operations

A join of two data sources is the association of objects in one data source with objects that share a common attribute in another data source.

Joining is an important operation in queries that target data sources whose relationships to each other cannot be followed directly. In object-oriented programming, this could mean a correlation between objects that is not modeled, such as the backwards direction of a one-way relationship. An example of a one-way relationship is a Customer class that has a property of type City, but the City class does not have a property that is a collection of Customer objects. If you have a list of City objects and you want to find all the customers in each city, you could use a join operation to find them.

The join methods provided in the LINQ framework are Join and GroupJoin. These methods perform equijoins, or joins that match two data sources based on equality of their keys. (For comparison, Transact-SQL supports join operators other than 'equals', for example the 'less than' operator.) In relational database terms, Join implements an inner join, a type of join in which only those objects that have a match in the other data set are returned. The GroupJoin method has no direct equivalent in relational database terms, but it implements a superset of inner joins and left outer joins. A left outer join is a join that returns each element of the first (left) data source, even if it has no correlated elements in the other data source.

The following illustration shows a conceptual view of two sets and the elements within those sets that are included in either an inner join or a left outer join.

Two overlapping circles showing inner/outer.

Method Name

Description

C# Query Expression Syntax

Visual Basic Query Expression Syntax

More Information

Join

Joins two sequences based on key selector functions and extracts pairs of values.

join … in … on … equals …

From x In …, y In … Where x.a = y.a

-or-

Join … [As …]In … On …

Enumerable.Join

Queryable.Join

GroupJoin

Joins two sequences based on key selector functions and groups the resulting matches for each element.

join … in … on … equals … into …

Group Join … In … On …

Enumerable.GroupJoin

Queryable.GroupJoin

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.