Method LeftJoin
LeftJoin<TOuter, TInner, TKey, TResult>(IQueryable<TOuter>, IQueryable<TInner>, Expression<Func<TOuter, TKey>>, Expression<Func<TInner, TKey>>, Expression<Func<TOuter, TInner, TResult>>)
Correlates the elements of two sequences based on matching keys, preserving all outer elements even when no matching inner element exists (left outer join semantics).
public static IQueryable<TResult> LeftJoin<TOuter, TInner, TKey, TResult>(this IQueryable<TOuter> outer, IQueryable<TInner> inner, Expression<Func<TOuter, TKey>> outerKeySelector, Expression<Func<TInner, TKey>> innerKeySelector, Expression<Func<TOuter, TInner, TResult>> resultSelector)
Parameters
outerIQueryable<TOuter>The first sequence to join.
innerIQueryable<TInner>The sequence to join to the first sequence.
outerKeySelectorExpression<Func<TOuter, TKey>>A function to extract the join key from each element of the first sequence.
innerKeySelectorExpression<Func<TInner, TKey>>A function to extract the join key from each element of the second sequence.
resultSelectorExpression<Func<TOuter, TInner, TResult>>A function to create a result element from an outer element and a matching inner element (or default if no match).
Returns
- IQueryable<TResult>
An IQueryable<T> that contains elements of type
TResultobtained by performing a left outer join on two sequences.
Type Parameters
TOuterThe type of the elements of the first sequence.
TInnerThe type of the elements of the second sequence.
TKeyThe type of the keys returned by the key selector functions.
TResultThe type of the result elements.
Remarks
When inner carries additional query operators (such as Where) it is translated to a
$lookup that combines localField/foreignField with a pipeline, which requires MongoDB 5.0 or later.