Repository navigation
Description
See dotnet/efcore#37633 for the EF/database motivation for this.
Background and motivation
LINQ provides Join (inner join), LeftJoin, and RightJoin, but no full outer join. A full outer join returns all elements from both sequences: matched elements are paired, while unmatched elements from either side appear with default for the missing counterpart. This is one of the most common relational join types and its absence forces users to write verbose, error-prone manual implementations combining LeftJoin with additional Except/Concat logic.
This proposal follows the same design established by LeftJoin/RightJoin (#113) and adds tuple-returning overloads per #120596.
API Proposal
namespace System.Linq;
public static partial class Enumerable
{
public static IEnumerable<TResult> FullJoin<TOuter, TInner, TKey, TResult>(
this IEnumerable<TOuter> outer,
IEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
Func<TOuter?, TInner?, TResult> resultSelector);
public static IEnumerable<TResult> FullJoin<TOuter, TInner, TKey, TResult>(
this IEnumerable<TOuter> outer,
IEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
Func<TOuter?, TInner?, TResult> resultSelector,
IEqualityComparer<TKey>? comparer);
public static IEnumerable<(TOuter? Outer, TInner? Inner)> FullJoin<TOuter, TInner, TKey>(
this IEnumerable<TOuter> outer,
IEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector);
public static IEnumerable<(TOuter? Outer, TInner? Inner)> FullJoin<TOuter, TInner, TKey>(
this IEnumerable<TOuter> outer,
IEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
IEqualityComparer<TKey>? comparer);
}
public static partial class Queryable
{
public static IQueryable<TResult> FullJoin<TOuter, TInner, TKey, TResult>(
this IQueryable<TOuter> outer,
IEnumerable<TInner> inner,
Expression<Func<TOuter, TKey>> outerKeySelector,
Expression<Func<TInner, TKey>> innerKeySelector,
Expression<Func<TOuter?, TInner?, TResult>> resultSelector);
public static IQueryable<TResult> FullJoin<TOuter, TInner, TKey, TResult>(
this IQueryable<TOuter> outer,
IEnumerable<TInner> inner,
Expression<Func<TOuter, TKey>> outerKeySelector,
Expression<Func<TInner, TKey>> innerKeySelector,
Expression<Func<TOuter?, TInner?, TResult>> resultSelector,
IEqualityComparer<TKey>? comparer);
public static IQueryable<(TOuter? Outer, TInner? Inner)> FullJoin<TOuter, TInner, TKey>(
this IQueryable<TOuter> outer,
IEnumerable<TInner> inner,
Expression<Func<TOuter, TKey>> outerKeySelector,
Expression<Func<TInner, TKey>> innerKeySelector);
public static IQueryable<(TOuter? Outer, TInner? Inner)> FullJoin<TOuter, TInner, TKey>(
this IQueryable<TOuter> outer,
IEnumerable<TInner> inner,
Expression<Func<TOuter, TKey>> outerKeySelector,
Expression<Func<TInner, TKey>> innerKeySelector,
IEqualityComparer<TKey>? comparer);
}namespace System.Linq;
public static partial class AsyncEnumerable
{
public static IAsyncEnumerable<TResult> FullJoin<TOuter, TInner, TKey, TResult>(
this IAsyncEnumerable<TOuter> outer,
IAsyncEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
Func<TOuter?, TInner?, TResult> resultSelector,
IEqualityComparer<TKey>? comparer = null);
public static IAsyncEnumerable<TResult> FullJoin<TOuter, TInner, TKey, TResult>(
this IAsyncEnumerable<TOuter> outer,
IAsyncEnumerable<TInner> inner,
Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector,
Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector,
Func<TOuter?, TInner?, CancellationToken, ValueTask<TResult>> resultSelector,
IEqualityComparer<TKey>? comparer = null);
public static IAsyncEnumerable<(TOuter? Outer, TInner? Inner)> FullJoin<TOuter, TInner, TKey>(
this IAsyncEnumerable<TOuter> outer,
IAsyncEnumerable<TInner> inner,
Func<TOuter, TKey> outerKeySelector,
Func<TInner, TKey> innerKeySelector,
IEqualityComparer<TKey>? comparer = null);
public static IAsyncEnumerable<(TOuter? Outer, TInner? Inner)> FullJoin<TOuter, TInner, TKey>(
this IAsyncEnumerable<TOuter> outer,
IAsyncEnumerable<TInner> inner,
Func<TOuter, CancellationToken, ValueTask<TKey>> outerKeySelector,
Func<TInner, CancellationToken, ValueTask<TKey>> innerKeySelector,
IEqualityComparer<TKey>? comparer = null);
}API Usage
// Result selector overload
var results = customers.FullJoin(
orders,
c => c.CustomerId,
o => o.CustomerId,
(customer, order) => new
{
CustomerName = customer?.Name ?? "(no customer)",
OrderId = order?.Id ?? 0
});
// Tuple overload (no result selector needed)
var pairs = customers.FullJoin(
orders,
c => c.CustomerId,
o => o.CustomerId);
foreach (var (customer, order) in pairs)
{
if (customer is not null && order is not null)
Console.WriteLine($"Matched: {customer.Name} - Order #{order.Id}");
else if (customer is not null)
Console.WriteLine($"Customer with no orders: {customer.Name}");
else
Console.WriteLine($"Orphaned order: #{order!.Id}");
}Design Decisions
- Result selector receives
TOuter?andTInner?(both nullable) — unlikeLeftJoinwhere only the inner side is nullable, orRightJoinwhere only the outer side is nullable. In a full join, either side can bedefault. - Tuple overloads return
(TOuter? Outer, TInner? Inner)— consistent with the tuple-returning overload pattern proposed in Add Join/LeftJoin/RightJoin overloads without a result selector, returning tuples #120596. - Algorithm uses
HashSet<Grouping>to track matched inner groupings —Grouping<TKey, TElement>is a sealed class so default reference equality works correctly. This avoids iterating the inner lookup twice. - Deferred execution — consistent with all other join operators.
Alternative Designs
Users can manually compose LeftJoin + RightJoin + filtering, but this is verbose, requires two passes over the inner sequence, and is error-prone. A dedicated FullJoin is more discoverable, efficient, and idiomatic.
Risks
- No source-breaking changes —
FullJoinis a new method name with no overload conflicts against existing LINQ operators. - No binary-breaking changes — purely additive.
Related Issues
- Introduce FullJoin() LINQ operator #124787 — Original issue requesting
FullJoin - Add Join/LeftJoin/RightJoin overloads without a result selector, returning tuples #120596 — Tuple-returning join overloads pattern
- Update readme #113 —
LeftJoin/RightJoinimplementation
Activity
dotnet-policy-service commentedon Feb 24, 2026
Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.
JamesFieldist commentedon Feb 24, 2026
viceroypenguin commentedon Feb 24, 2026
roji commentedon Feb 25, 2026
Add FullJoin LINQ operator
eiriktsarpalis commentedon Feb 25, 2026
Note
This proposal was drafted with the help of an AI agent. Please review for accuracy and remove this notice once you're satisfied with the content.
API Proposal:
FullJoinLINQ OperatorBackground and motivation
LINQ provides
Join(inner join),LeftJoin, andRightJoin, but no full outer join. A full outer join returns all elements from both sequences: matched elements are paired, while unmatched elements from either side appear withdefaultfor the missing counterpart. This is one of the most common relational join types and its absence forces users to write verbose, error-prone manual implementations combiningLeftJoinwith additionalExcept/Concatlogic.This proposal follows the same design established by
LeftJoin/RightJoin(#113) and adds tuple-returning overloads per #120596.API Proposal
API Usage
Design Decisions
TOuter?andTInner?(both nullable) — unlikeLeftJoinwhere only the inner side is nullable, orRightJoinwhere only the outer side is nullable. In a full join, either side can bedefault.(TOuter? Outer, TInner? Inner)— consistent with the tuple-returning overload pattern proposed in Add Join/LeftJoin/RightJoin overloads without a result selector, returning tuples #120596.HashSet<Grouping>to track matched inner groupings —Grouping<TKey, TElement>is a sealed class so default reference equality works correctly. This avoids iterating the inner lookup twice.Alternative Designs
Users can manually compose
LeftJoin+RightJoin+ filtering, but this is verbose, requires two passes over the inner sequence, and is error-prone. A dedicatedFullJoinis more discoverable, efficient, and idiomatic.Risks
FullJoinis a new method name with no overload conflicts against existing LINQ operators.Related Issues
FullJoinLeftJoin/RightJoinimplementationPrototype
eiriktsarpalis@26b48d9
fowl2 commentedon Feb 26, 2026
shouldn't it be "left" and "right" instead of "inner" and "outer"?
roji commentedon Feb 26, 2026
@fowl2 I'm assuming you're referring to the parameter names; if so, then no - these should be outer and inner, following the naming on the existing Join/LeftJoin/RightJoin operators (docs).
All joins receive two sequences as their input - the outer and the inner; they then perform a different kind of join on them (inner, left, right, full). In the LINQ context, outer simply refers to the sequence being the "source", i.e. the first parameter (and the one that acts as the "instance" for the extension method).
fowl2 commentedon Feb 27, 2026
@roji yes, both the the type and (regular) parameter names.
For "left" (outer) and "right" (outer) joins the "inner" unambiguously refers to the "Left" and "Right, respectively. They have defined semantic meaning - inner meaning the collection from which all elements will be returned, and outer from which only there are matches.
For a full (outer) join there is no "inner" and "outer", they are both "outer".
It's unfortunate that (inner)
Joinhas used "inner" and "outer" and obviously we can't change them now, but I'm not sure the I see the value of consistency over meaning here.roji commentedon Feb 27, 2026
That's the main point here; given how the original (inner) Enumerable.Join names its parameters, in LINQ "outer" just means "first", rather than "the sequence whose elements are preserved regardless of the other sequence". I agree with you that this is inconsistent with the SQL naming and I'd have likely named the (inner) Join parameters left/right instead, but as you say it is what it is and cannot be changed.
But I do believe it's better to just continue with that naming with the new join operators, rather than suddenly have FullJoin have left/right where the other Joins have outer/inner.
Add an api-proposal Copilot skill (#124808)
bartonjs commentedon Apr 20, 2026
@roji or @eiriktsarpalis Please update the top post before tomorrow morning (Redmond time) to have the API you want to discuss. Since it needs a human owner/sponsor, you can remove the "AI helped write this" disclaimer.
bartonjs commentedon Apr 21, 2026
Video
Implement LINQ FullJoin operators (#127236)
Implement LINQ FullJoin operators (#127236)