Skip to content

Introduce FullJoin() LINQ operator #124787

Closed

Description

@roji

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? and TInner? (both nullable) — unlike LeftJoin where only the inner side is nullable, or RightJoin where only the outer side is nullable. In a full join, either side can be default.
  • 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 — FullJoin is a new method name with no overload conflicts against existing LINQ operators.
  • No binary-breaking changes — purely additive.

Related Issues

Prototype

eiriktsarpalis@26b48d9

Activity

  1. added this to the 11.0.0 milestone on Feb 24, 2026
  2. added theissue type on Feb 24, 2026
  3. dotnet-policy-service commented on Feb 24, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-linq
    See info in area-owners.md if you want to be subscribed.

  4. JamesFieldist commented on Feb 24, 2026

    @JamesFieldist
  5. viceroypenguin commented on Feb 24, 2026

    @viceroypenguin
  6. roji commented on Feb 25, 2026

    @roji
    Author
  7. added a commit that references this issue on Feb 25, 2026
  8. eiriktsarpalis commented on Feb 25, 2026

    @eiriktsarpalis
    Member

    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: FullJoin LINQ Operator

    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? and TInner? (both nullable) — unlike LeftJoin where only the inner side is nullable, or RightJoin where only the outer side is nullable. In a full join, either side can be default.
    • 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 — FullJoin is a new method name with no overload conflicts against existing LINQ operators.
    • No binary-breaking changes — purely additive.

    Related Issues

    Prototype

    eiriktsarpalis@26b48d9

  9. added
    api-ready-for-review
    on Feb 25, 2026
  10. fowl2 commented on Feb 26, 2026

    @fowl2

    shouldn't it be "left" and "right" instead of "inner" and "outer"?

  11. roji commented on Feb 26, 2026

    @roji
    MemberAuthor

    @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).

  12. fowl2 commented on Feb 27, 2026

    @fowl2

    @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) Join has 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.

  13. roji commented on Feb 27, 2026

    @roji
    MemberAuthor

    It's unfortunate that (inner) Join has 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.

    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.

  14. bartonjs commented on Apr 20, 2026

    @bartonjs
    Member

    @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.

  15. bartonjs commented on Apr 21, 2026

    @bartonjs
    Member

    Video

    • In SQL terminology, "inner" and "outer" don't seem like the correct terms, but since "Join" (SQL INNER JOIN) already used "outer" as the "this" and "inner" as the "other" (instead of "left" and "right"), so the names seem right here.
    • We've already started using default parameters in System.Linq.Enumerable, so let's collapse the overloads down and default the comparer
    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,
            IEqualityComparer<TKey>? comparer = null);
    
        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 = null);
    }
    
    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,
            IEqualityComparer<TKey>? comparer = null);
    
        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 = null);
    }
    
    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);
    }
  16. added
    api-approved
    and removed
    api-ready-for-review
    on Apr 21, 2026
  17. added a commit that references this issue on May 18, 2026
    1d2108d
  18. locked and limited conversation to collaborators on Jun 18, 2026
  19. added a commit that references this issue on Jul 15, 2026
    089f234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api-approvedarea-System.Linq

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions