Repository navigation
Fall back to a subquery for GroupBy element orderings and predicates over owned types in their own table - #39835
Open
jeremy-morren wants to merge 1 commit into
Open
jeremy-morren wants to merge 1 commit into
jeremy-morren wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The review has no active issues requiring resolution.
No open issues 🎉
What changed in this PR
Fixes #39833 by extending EF Core’s relational GroupBy translation fallback to orderings and predicates over owned types mapped to separate tables. This builds on #38918 without adding joins directly to the grouped query.
Changes:
- Centralizes suppression of unbound
EF.Propertyerrors inTranslateAggregateArgument, restoring the previous setting afterward. - Adds shared regression tests for
OrderByDescending(...).First(),MaxBy,Max, and predicate-basedCount. - Adds SQL Server baselines across association mappings and Cosmos assertions for unsupported GroupBy translation.
| File | Description |
|---|---|
test/EFCore.SqlServer.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingMiscellaneousSqlServerTest.cs |
Adds baselines for table-split owned types. |
test/EFCore.SqlServer.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsMiscellaneousSqlServerTest.cs |
Verifies separate-table owned types use subquery fallback. |
test/EFCore.SqlServer.FunctionalTests/Query/Associations/OwnedJson/OwnedJsonMiscellaneousSqlServerTest.cs |
Adds baselines for JSON-mapped owned types. |
test/EFCore.SqlServer.FunctionalTests/Query/Associations/OwnedComplexProperties/OwnedComplexPropertiesMiscellaneousSqlServerTest.cs |
Adds baselines for mixed owned and complex mappings. |
test/EFCore.SqlServer.FunctionalTests/Query/Associations/Navigations/NavigationsMiscellaneousSqlServerTest.cs |
Adds baselines for regular navigation properties. |
test/EFCore.SqlServer.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingMiscellaneousSqlServerTest.cs |
Adds baselines for table-split complex types. |
test/EFCore.SqlServer.FunctionalTests/Query/Associations/ComplexJson/ComplexJsonMiscellaneousSqlServerTest.cs |
Adds baselines for JSON-mapped complex types. |
test/EFCore.Specification.Tests/Query/Associations/AssociationsMiscellaneousTestBase.cs |
Defines four shared GroupBy regression tests. |
test/EFCore.Cosmos.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsMiscellaneousCosmosTest.cs |
Asserts existing GroupBy limitations for owned navigations. |
test/EFCore.Cosmos.FunctionalTests/Query/Associations/OwnedComplexProperties/OwnedComplexPropertiesMiscellaneousCosmosTest.cs |
Asserts existing GroupBy limitations for mixed mappings. |
test/EFCore.Cosmos.FunctionalTests/Query/Associations/ComplexProperties/ComplexPropertiesMiscellaneousCosmosTest.cs |
Asserts existing GroupBy limitations for complex properties. |
src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs |
Enables shared subquery fallback while preserving error-handling state. |
Review effort: Balanced
…over owned types in their own table Over a grouping element, an owned type that needs a join is left unexpanded, so its property doesn't bind. Aggregate selectors already translated with the EF.Property error turned off and fell back to a subquery, but orderings, predicates and Any/All threw instead. TranslateAggregateArgument, which all of them share, now turns the error off itself and restores it afterwards. Fixes dotnet#39833 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jeremy-morren
force-pushed
the
fix-owned-own-table-groupby
branch
from
November 27, 2026 06:33
49608f8 to
87ec5f5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ordering or filtering a group's elements by a member of an owned type mapped to its own table (
g.OrderByDescending(e => e.Created.At).First(),g.MaxBy(...),g.Count(e => e.Created.At > x)) threw "Translation of 'EF.Property<...>' failed" instead of falling back to a subquery.g.Max(e => e.Created.At)) already handled this by translating with the EF.Property error turned off, and fell back to a subquery; orderings, predicates andAny/Alldidn't, so they threw.TranslateAggregateArgument, which all of these share, now turns the error off itself and restores the previous setting afterwards. All of them now fall back to the subquery, which joins the owned table in.OrderByDescending(...).First(),MaxBy,Max,Countwith a predicate) to the shared associations tests.Fixes #39833