Skip to content

Fix projecting complex type in ProjectionBinder#37552

Merged
roji merged 1 commit intodotnet:mainfrom
roji:37551
Feb 3, 2026
Merged

Fix projecting complex type in ProjectionBinder#37552
roji merged 1 commit intodotnet:mainfrom
roji:37551

Conversation

@roji
Copy link
Member

@roji roji commented Jan 23, 2026

Fixes #37551

@roji roji requested a review from a team as a code owner January 23, 2026 11:11
Copilot AI review requested due to automatic review settings January 23, 2026 11:11
@roji roji enabled auto-merge (squash) January 23, 2026 11:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@roji roji merged commit 0555efa into dotnet:main Feb 3, 2026
15 of 16 checks passed
@roji roji deleted the 37551 branch February 3, 2026 01:39
roji added a commit to roji/efcore that referenced this pull request Feb 3, 2026
@roji roji mentioned this pull request Feb 3, 2026
roji added a commit that referenced this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessary Columns in generated SQL with Complex Types + Object Closures in Projections

2 participants

Comments