Uh oh!
There was an error while loading. Please reload this page.
Reinstate LINQ join convenience overloads and fix the build break - #126649
Conversation
Implements tuple-returning overloads for `Join`, `LeftJoin`, and `RightJoin` that eliminate the need for a `resultSelector` lambda when you just want the joined elements as a tuple. ## Changes - **System.Linq.Enumerable**: Added `Join<TOuter, TInner, TKey>`, `LeftJoin<TOuter, TInner, TKey>`, `RightJoin<TOuter, TInner, TKey>` returning `(TOuter Outer, TInner Inner)` tuples (with nullable element for outer joins) - **System.Linq.Queryable**: Added corresponding overloads with `Expression<Func<>>` key selectors - **System.Linq.AsyncEnumerable**: Added overloads for both sync and async key selector variants - All methods use a single overload with an optional `IEqualityComparer<TKey>? comparer = null` parameter ## Example Before: ```csharp foreach (var (s, pair) in keys.Join(dict, k => k, p => p.Value, (outer, inner) => (outer, inner))) Console.WriteLine(s + " : " + pair.Key); ``` After: ```csharp foreach (var (s, pair) in keys.Join(dict, k => k, p => p.Value)) Console.WriteLine(s + " : " + pair.Key); ``` Fixesdotnet#120596 <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> ---- *This section details on the original issue you should resolve* <issue_title>[API Proposal]: Linq Join return tuple similar to Zip</issue_title> <issue_description>### Background and motivation For simplicity of `Join` it should just return `(TOuter,TInner)` instead of the need for `resultSelector` ### API Proposal ```csharp namespace System.Linq; public static class Enumerable { public static IEnumerable<(TOuter Outer, TInner Inner)> Join<TOuter, TInner, TKey>( this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, IEqualityComparer<TKey>? comparer = null); public static IEnumerable<(TOuter Outer, TInner? Inner)> LeftJoin<TOuter, TInner, TKey>( this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, IEqualityComparer<TKey>? comparer = null); public static IEnumerable<(TOuter? Outer, TInner Inner)> RightJoin<TOuter, TInner, TKey>( this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, IEqualityComparer<TKey>? comparer = null); } public static class Queryable { public static IQueryable<(TOuter Outer, TInner Inner)> Join<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 IQueryable<(TOuter Outer, TInner? Inner)> LeftJoin<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 IQueryable<(TOuter? Outer, TInner Inner)> RightJoin<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 class AsyncEnumerable { public static IAsyncEnumerable<(TOuter Outer, TInner Inner)> Join<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); public static IAsyncEnumerable<(TOuter Outer, TInner Inner)> Join<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)> LeftJoin<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); public static IAsyncEnumerable<(TOuter Outer, TInner? Inner)> LeftJoin<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)> RightJoin<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); public static IAsyncEnumerable<(TOuter? Outer, TInner Inner)> RightJoin<TOuter, TInner, TKey>( this IAsyncEnumerable<TOuter> outer, IAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, IEqualityComparer<TKey>? comparer = null); } ``` ### API Usage ```csharp var keys = new[] { "x" ,"y" ,"z" }; var dict = new Dictionary<int,string>(); foreach (var (s,pair) in keys.Join(dict,(key) => key,(pair) => pair.Value)) Console.WriteLine(s + " : " pair.Key); ``` ### Alternative Designs Without this it need to make another lambda just for return tuple ```C# foreach (var (s,pair) in keys.Join(dict,(key) => key,(pair) => pair.Value,(outer,inner) => (outer,inner))) Console.WriteLine(s + " : " pair.Key); ```... </details> - Fixesdotnet#120596 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/runtime/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> Co-authored-by: Shay Rojansky <roji@roji.org> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com> (cherry picked from commit 2916d73)
Implements the approved API from dotnet#120587 — a simplified `GroupJoin` overload that removes the need for an explicit result selector, returning `IGrouping<TOuter, TInner>` where the outer element is the key and the correlated inner elements are the grouping contents. ## Description ### API ```csharp namespace System.Linq; public static partial class Enumerable { public static IEnumerable<IGrouping<TOuter, TInner>> GroupJoin<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<IGrouping<TOuter, TInner>> GroupJoin<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<IGrouping<TOuter, TInner>> GroupJoin<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<IGrouping<TOuter, TInner>> GroupJoin<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); } ``` ### Changes - **System.Linq**: New `GroupJoin<TOuter,TInner,TKey>` overload with optional `IEqualityComparer<TKey>?` parameter + internal `GroupJoinGrouping<TKey, TElement>` wrapper class. XML doc comments with correct `<see cref="IGrouping{TOuter, TInner}"/>` references added to the new public API. - **System.Linq.Queryable**: New overload with optional `IEqualityComparer<TKey>?` parameter and `[DynamicDependency]` on `Enumerable.GroupJoin`3`. XML doc comments added. - **System.Linq.AsyncEnumerable**: Two new overloads (sync and async key selector variants) with optional `IEqualityComparer<TKey>?` parameter + internal `AsyncGroupJoinGrouping<TKey, TElement>` wrapper class. XML doc comments added. - Reference assemblies updated for all three projects. - Tests for all three projects, with `#if NET` guards in the async enumerable tests for net481 compatibility (the new `Enumerable.GroupJoin` overload and tuple-returning `Zip` are unavailable on .NET Framework 4.8.1). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com> Co-authored-by: Shay Rojansky <roji@roji.org> Co-authored-by: roji <1862641+roji@users.noreply.github.com> Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com> (cherry picked from commit 375857b)
Tagging subscribers to this area: @dotnet/area-system-linq |
There was a problem hiding this comment.
Pull request overview
This PR reinstates previously reverted LINQ “convenience” overloads for Join/LeftJoin/RightJoin (tuple-returning) and GroupJoin (returning IGrouping without a result selector), and addresses the System.Linq.AsyncEnumerable multi-target test build break by making some overload calls more explicit.
Changes:
- Add tuple-returning
Join/LeftJoin/RightJoinoverloads acrossEnumerable,Queryable, andAsyncEnumerable. - Add
GroupJoinoverload returningIEnumerable/IQueryable/IAsyncEnumerable<IGrouping<...>>without aresultSelector. - Extend/adjust tests and update reference assemblies to reflect the reinstated public APIs.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Linq/tests/RightJoinTests.cs | Adds coverage for tuple-returning Enumerable.RightJoin overload. |
| src/libraries/System.Linq/tests/LeftJoinTests.cs | Adds coverage for tuple-returning Enumerable.LeftJoin overload. |
| src/libraries/System.Linq/tests/JoinTests.cs | Adds coverage for tuple-returning Enumerable.Join overload. |
| src/libraries/System.Linq/tests/GroupJoinTests.cs | Adds coverage for selector-less Enumerable.GroupJoin returning IGrouping. |
| src/libraries/System.Linq/src/System/Linq/RightJoin.cs | Implements tuple-returning Enumerable.RightJoin overload and iterator. |
| src/libraries/System.Linq/src/System/Linq/LeftJoin.cs | Implements tuple-returning Enumerable.LeftJoin overload and iterator. |
| src/libraries/System.Linq/src/System/Linq/Join.cs | Implements tuple-returning Enumerable.Join overload and iterator. |
| src/libraries/System.Linq/src/System/Linq/GroupJoin.cs | Implements selector-less Enumerable.GroupJoin returning IGrouping + wrapper grouping type. |
| src/libraries/System.Linq/ref/System.Linq.cs | Updates System.Linq reference assembly with new overloads. |
| src/libraries/System.Linq.Queryable/tests/RightJoinTests.cs | Adds coverage for tuple-returning Queryable.RightJoin overload. |
| src/libraries/System.Linq.Queryable/tests/LeftJoinTests.cs | Adds coverage for tuple-returning Queryable.LeftJoin overload. |
| src/libraries/System.Linq.Queryable/tests/JoinTests.cs | Adds coverage for tuple-returning Queryable.Join overload. |
| src/libraries/System.Linq.Queryable/tests/GroupJoinTests.cs | Adds coverage for selector-less Queryable.GroupJoin returning IGrouping. |
| src/libraries/System.Linq.Queryable/src/System/Linq/Queryable.cs | Adds Queryable overloads for tuple joins and selector-less GroupJoin (+ dependencies). |
| src/libraries/System.Linq.Queryable/ref/System.Linq.Queryable.cs | Updates System.Linq.Queryable reference assembly with new overloads. |
| src/libraries/System.Linq.AsyncEnumerable/tests/RightJoinTests.cs | Adds tests for tuple-returning AsyncEnumerable.RightJoin and explicit-call patterns for multi-targeting. |
| src/libraries/System.Linq.AsyncEnumerable/tests/LeftJoinTests.cs | Adds tests for tuple-returning AsyncEnumerable.LeftJoin and explicit-call patterns for multi-targeting. |
| src/libraries/System.Linq.AsyncEnumerable/tests/JoinTests.cs | Adds tests for tuple-returning AsyncEnumerable.Join and explicit-call patterns for multi-targeting. |
| src/libraries/System.Linq.AsyncEnumerable/tests/GroupJoinTests.cs | Adds tests for selector-less AsyncEnumerable.GroupJoin returning IGrouping. |
| src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/RightJoin.cs | Implements tuple-returning AsyncEnumerable.RightJoin overloads (sync+async key selectors). |
| src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/LeftJoin.cs | Implements tuple-returning AsyncEnumerable.LeftJoin overloads (sync+async key selectors). |
| src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/Join.cs | Implements tuple-returning AsyncEnumerable.Join overloads (sync+async key selectors). |
| src/libraries/System.Linq.AsyncEnumerable/src/System/Linq/GroupJoin.cs | Implements selector-less AsyncEnumerable.GroupJoin returning IGrouping + wrapper grouping type. |
| src/libraries/System.Linq.AsyncEnumerable/ref/System.Linq.AsyncEnumerable.cs | Updates System.Linq.AsyncEnumerable reference assembly with new overloads. |
f53841d to
2ca6583CompareCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2ca6583 to
bca206bCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The resultSelector lambda had its parameter names swapped relative to the actual (outer, inner) positions, producing reversed concatenation in the expected sequence. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eiriktsarpalis
commented
Apr 29, 2026
/ba-g test failures are unrelated. |
Uh oh!
There was an error while loading. Please reload this page.
Note
This PR description was generated with Copilot.
Reinstates the LINQ convenience overloads from #121998 and #121999 that were reverted in #126624, while also fixing the build break that caused the revert.
Summary
System.Linq.AsyncEnumerabletest build break by making the affected async selectorless overload calls explicit where inference was insufficient during the multi-target buildValidation
build.cmd clr+libs -rc release.\dotnet.cmd build .\src\libraries\System.Linq.AsyncEnumerable\tests\System.Linq.AsyncEnumerable.Tests.csproj /t:Test --no-restore.\dotnet.cmd build .\src\libraries\System.Linq\tests\System.Linq.Tests.csproj /t:Test --no-restore.\dotnet.cmd build .\src\libraries\System.Linq.Queryable\tests\System.Linq.Queryable.Tests.csproj /t:Test --no-restore