Fix UseProjection over-projecting when the entity is a record#9889
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an EF Core projection regression where UseProjection over-selected all mapped columns for non-positional C# record entities by ensuring the instance-reuse heuristic does not treat the compiler-generated record copy constructor as a constructor-injection signal.
Changes:
- Update
QueryableProjectionScopeExtensions.ShouldReuseExistingInstanceto ignore record copy constructors (protected R(R original)). - Add an EF+SQLite regression test asserting SQL only selects the requested column for a record entity.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/HotChocolate/Data/test/Data.EntityFramework.Tests/IntegrationTests.cs |
Adds a regression test that captures generated SQL for a record entity projection and verifies only the selected column is projected. |
src/HotChocolate/Data/src/Data/Projections/Expressions/QueryableProjectionScopeExtensions.cs |
Adjusts the “reuse existing instance” heuristic to exclude record copy constructors, preventing the selector from degrading into an identity projection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jun 16, 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.
Summary
UseProjectionprojected every mapped column when the entity type was a non-positional C# record, ignoring the GraphQL selection set.protected R(R original)) as an injection constructor, turning the selector into an identity expression.ShouldReuseExistingInstanceinQueryableProjectionScopeExtensionsnow excludes record copy constructors, mirroring the equivalent fix already made forQueryContextselectors in Fix QueryContext selector for record projections #9459.Test plan
SELECT "p"."Id", "p"."Description", "p"."Name"before the fix, nowSELECT "p"."Id").Closes #9886