[release/10.0] Fix projection of entities with complex collections through subqueries#37747
Merged
roji merged 1 commit intodotnet:release/10.0from Feb 24, 2026
Merged
[release/10.0] Fix projection of entities with complex collections through subqueries#37747roji merged 1 commit intodotnet:release/10.0from
roji merged 1 commit intodotnet:release/10.0from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where projecting entities with complex collections (mapped to JSON) through subqueries throws an UnreachableException. The issue was introduced with the new complex collections mapped to JSON feature in EF 10, where ClientProjectionRemappingExpressionVisitor didn't handle IComplexProperty when processing CollectionResultExpression.StructuralProperty.
Changes:
- Fixed
ClientProjectionRemappingExpressionVisitorto handleIComplexPropertyby treating it like null (since complex properties aren't navigations) - Added test coverage for projecting complex collections through subqueries
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs | Fixed switch expression to handle IComplexProperty case by treating it as null navigation |
| test/EFCore.Specification.Tests/Query/Associations/AssociationsProjectionTestBase.cs | Added base test for selecting complex collection through subquery with FirstOrDefault |
| test/EFCore.SqlServer.FunctionalTests/Query/Associations/ComplexJson/ComplexJsonProjectionSqlServerTest.cs | Added SQL Server test implementation with SQL baseline verification |
| test/EFCore.Sqlite.FunctionalTests/Query/Associations/ComplexJson/ComplexJsonProjectionSqliteTest.cs | Added SQLite test override that correctly expects OUTER APPLY not supported error |
AndriySvyryd
approved these changes
Feb 20, 2026
artl93
approved these changes
Feb 20, 2026
Member
artl93
left a comment
There was a problem hiding this comment.
New scenario. Customer reported. Approved. That doesn't look like a reasonable workaround.
This was referenced Feb 25, 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 #37725
Description
Projecting an entity with a complex collection (mapped to JSON via
ComplexCollection+ToJson()through a subquery (e.g.,FirstOrDefault()throws UnreachableException because ClientProjectionRemappingExpressionVisitor does not handleIComplexPropertywhen extracting the navigation from aCollectionResultExpression.StructuralProperty.Customer impact
Customers who migrated from owned entity types to complex collection types (as recommended in the EF 10 release notes) cannot project entities with complex collections through subqueries. The query throws UnreachableException: The program executed an instruction that was thought to be unreachable.
Querying the entity directly (without going through a parent navigation/subquery) works fine. There is no workaround other than reverting to owned entity types or restructuring queries to avoid subquery projections.
How found
Customer reported on 10.0
Regression
No, complex collections mapped to JSON is a new feature in EF 10.
Testing
Test added.
Risk
Extremely low; single line fix to handle a case that otherwise immediately throws UnreachableException (quirk makes no sense).