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-enumerable
joininner-var in inner-enumerable
onouter-key-expr
equalsinner-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 ...
Get LINQ Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.