O'Reilly logo

LINQ Pocket Reference by Joseph Albahari, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Joining

Method

Description

SQL equivalents

Join

Applies a lookup strategy to match elements from two collections, emitting a flat result set

INNER JOIN

Group Join

As above, but emits a hierarchical result set

INNER JOIN, LEFT OUTER JOIN

Join and GroupJoin

Join arguments

Argument

Type

Outer sequence

IEnumerable<TOuter>

Inner sequence

IEnumerable<TInner>

Outer key selector

TOuter => TKey

Inner key selector

TInner => TKey

Result selector

(TOuter,TInner) => TResult

GroupJoin arguments

Argument

Type

Outer sequence

IEnumerable<TOuter>

Inner sequence

IEnumerable<TInner>

Outer key selector

TOuter => TKey

Inner key selector

TInner => TKey

Result selector

(TOuter,IEnumerable<TInner>) => Tresult

Return type = IEnumerable<TResult>

Comprehension syntax

	from outer-var in outer-enumerable
	join inner-var in inner-enumerable
	  on outer-key-expr equals inner-key-expr
	 [ into identifier ]

Overview

Join and GroupJoin mesh two input sequences into a single output sequence. Join emits flat output; GroupJoin emits hierarchical output.

Join and GroupJoin provide an alternative strategy to Select and SelectMany. The advantage of Join and GroupJoin is that they execute efficiently over local in-memory collections because they first load the inner sequence into a keyed lookup, avoiding the need to repeatedly enumerate over every inner element. Their disadvantage is that they offer the equivalent of inner and left outer joins only; cross joins and non-equi joins must still be done with Select /SelectMany. With LINQ to SQL ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required