Joining
Method | Description | SQL equivalents |
|---|---|---|
| Applies a lookup strategy to match elements from two collections, emitting a flat result set | |
| As above, but emits a hierarchical result set | |
Join and GroupJoin
Join arguments
Argument | Type |
|---|---|
Outer sequence | |
Inner sequence | |
Outer key selector | |
Inner key selector | |
Result selector | |
GroupJoin arguments
Argument | Type |
|---|---|
Outer sequence | |
Inner sequence | |
Outer key selector | |
Inner key selector | |
Result selector | ( |
Return type =
IEnumerable<TResult>
Comprehension syntax
fromouter-var in outer-enumerablejoininner-var in inner-enumerableonouter-key-exprequalsinner-key-expr[ intoidentifier]
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access