Skip to content

[release/11.0] Fix projecting JSON complex collection together with collection navigation - #38948

Open
AndriySvyryd with Copilot wants to merge 1 commit into
release/11.0from
copilot/servicing-pr
Open

[release/11.0] Fix projecting JSON complex collection together with collection navigation#38948
AndriySvyryd with Copilot wants to merge 1 commit into
release/11.0from
copilot/servicing-pr

Conversation

Copilot AI commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #38928
Backports #38932

Description
When a query projects a JSON complex collection (ComplexCollection(...).ToJson()) together with a collection navigation in the same Select(), the index-based client-projection path added a ProjectionBindingExpression referencing the collection's _projectionMembers position instead of its position in _clientProjections. When both a JSON complex collection and a collection navigation are projected together, ClientProjectionRemappingExpressionVisitor tries to look up the projection by that (wrong) index and finds no match, throwing InvalidOperationException: Nullable object must have a value.

Customer impact
Any query that projects a JSON-mapped complex collection alongside a collection navigation in the same Select() fails at translation time (even calling ToQueryString() throws), so the query cannot be used at all. There's no workaround other than splitting the projections across multiple round trips.

How found
User reported on 11.0.0-preview.7.

Regression
Yes, from 10.0.*, possibly exposed by #37552

Testing
Tests added

Risk
Low. The fix is a small, targeted change to the index-based binding branch for JSON complex collections, mirroring the pattern already used for JSON reference navigations a few lines above.

…ation (#38928)

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [release/11.0] Fix projecting JSON complex collection together with collection navigation Fix projecting JSON complex collection together with collection navigation Sep 9, 2026
Copilot AI requested a review from AndriySvyryd September 9, 2026 20:59
@AndriySvyryd AndriySvyryd changed the title Fix projecting JSON complex collection together with collection navigation [release/11.0] Fix projecting JSON complex collection together with collection navigation Sep 9, 2026
@AndriySvyryd
AndriySvyryd marked this pull request as ready for review September 9, 2026 21:59
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner September 9, 2026 21:59
Copilot AI lite review requested due to automatic review settings September 9, 2026 21:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The fix aligns with the established index-based client projection remapping mechanism and is covered by new relational/spec plus provider baseline tests.

Pull request overview

Backports a relational query translation fix for projecting a JSON-mapped complex collection alongside a collection navigation in the same Select(), addressing an InvalidOperationException during client-projection remapping.

Changes:

  • Fix index-based projection binding for CollectionResultExpression over JsonQueryExpression to bind using the _clientProjections index.
  • Add a relational spec test covering the combined JSON complex collection + collection navigation projection scenario.
  • Add provider-specific SQL baselines for SQL Server and SQLite for the new test.
File summaries
File Description
src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs Fixes index-based binding to return a ProjectionBindingExpression keyed by client-projection index for JSON complex collections.
test/EFCore.Relational.Specification.Tests/Query/ComplexTypeQueryRelationalTestBase.cs Adds a regression test for projecting JSON complex collections together with a collection navigation under split query.
test/EFCore.SqlServer.FunctionalTests/Query/ComplexTypeQuerySqlServerTest.cs Adds SQL Server baseline assertions for the new regression test.
test/EFCore.Sqlite.FunctionalTests/Query/ComplexTypeQuerySqliteTest.cs Adds SQLite baseline assertions for the new regression test.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

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.

3 participants