Fix projecting complex type in ProjectionBinder#37552
Merged
roji merged 1 commit intodotnet:mainfrom Feb 3, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #37551 where EF Core was including unnecessary columns in generated SQL when projecting complex types alongside non-primitive closure variables (reference type closures). The bug affected performance, especially with TPH hierarchies, and directly impacted ASP.NET Core OData's $select functionality.
Changes:
- Modified projection binding logic to properly handle complex types returned by
TranslateProjection - Added comprehensive test coverage across multiple association patterns and database providers
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs | Fixed complex type projection by handling RelationalStructuralTypeShaperExpression and CollectionResultExpression cases with base.Visit() instead of treating them as scalar SQL expressions |
| test/EFCore.Specification.Tests/Query/Associations/AssociationsProjectionTestBase.cs | Added new test case Select_associate_and_target_to_index_based_binding_via_closure that reproduces the bug scenario with an object closure |
| test/EFCore.Specification.Tests/Query/Associations/OwnedNavigations/OwnedNavigationsProjectionTestBase.cs | Added override to ensure proper tracking behavior for the new test in owned navigation scenarios |
| test/EFCore.SqlServer.FunctionalTests/Query/Associations/ComplexTableSplitting/ComplexTableSplittingProjectionSqlServerTest.cs | Updated SQL baselines showing removal of unnecessary columns (Id, Name, OptionalAssociate fields) and added SQL verification for the new test |
| test/EFCore.SqlServer.FunctionalTests/Query/Associations/ComplexJson/ComplexJsonProjectionSqlServerTest.cs | Updated SQL baselines and added test override demonstrating minimal column selection with complex JSON |
| test/EFCore.SqlServer.FunctionalTests/Query/Associations/OwnedTableSplitting/OwnedTableSplittingProjectionSqlServerTest.cs | Added SQL baseline verification for owned types with table splitting |
| test/EFCore.SqlServer.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsProjectionSqlServerTest.cs | Added SQL baseline verification for owned navigations |
| test/EFCore.SqlServer.FunctionalTests/Query/Associations/Navigations/NavigationsProjectionSqlServerTest.cs | Added SQL baseline verification for regular entity navigations |
| test/EFCore.Cosmos.FunctionalTests/Query/Associations/OwnedNavigations/OwnedNavigationsProjectionCosmosTest.cs | Documented known Cosmos provider limitation with the scenario (expects EqualException for non-tracking queries) |
AndriySvyryd
approved these changes
Feb 3, 2026
roji
added a commit
to roji/efcore
that referenced
this pull request
Feb 3, 2026
roji
added a commit
that referenced
this pull request
Feb 3, 2026
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.
Fixes #37551