Skip to content

Fix complex property projection for entity splitting mappings#38592

Draft
AndriySvyryd with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-entity-splitting-complex-property
Draft

Fix complex property projection for entity splitting mappings#38592
AndriySvyryd with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-entity-splitting-complex-property

Conversation

Copilot AI commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Queries over split entities (SplitToTable) with a non-JSON ComplexProperty could fail during relational projection with Sequence contains more than one element.
The failure came from assuming a single complex-type mapping table in the split-entity projection path.

  • Root cause in relational projection

    • CreateSelect (entity-splitting branch) selected the complex property table via:
      • complexProperty.ComplexType.GetQueryMappings().Single().Table
    • Under split mappings, that assumption is invalid and can produce ambiguous/multiple mappings.
  • Query pipeline change

    • Replaced single-mapping table selection with table resolution based on actual mapped columns in projected mappings.
    • Added FindTable/TryFindTable helpers to resolve the table by:
      1. JSON container column (for JSON complex types),
      2. concrete complex properties,
      3. nested complex properties recursively,
      4. fallback to previous mapping-based behavior when no mapped column is found.
  • Regression coverage

    • Added Complex_property_on_split_entity in AdHocComplexTypeQueryRelationalTestBase.
    • Scenario models Hook + HookMetadata split table with Hook.Number as complex type, and asserts materialization of both root and complex members.
// Before (assumed one mapping table)
var table = complexProperty.ComplexType.GetQueryMappings().Single().Table;

// After (resolve from projected mappings/columns)
var table = FindTable(complexProperty, mappings);

Copilot AI and others added 2 commits July 9, 2026 01:38
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…tion

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix InvalidOperationException when using complex property Fix complex property projection for entity splitting mappings Jul 9, 2026
Copilot AI requested a review from AndriySvyryd July 9, 2026 01:44
@AndriySvyryd AndriySvyryd requested a review from Copilot July 9, 2026 17:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a relational query translation failure when projecting complex properties on split entities (SplitToTable) by resolving the complex property’s table based on actual mapped columns rather than assuming a single complex-type table mapping.

Changes:

  • Updated the entity-splitting projection path in CreateSelect to determine the complex-property table via new FindTable/TryFindTable helpers using mapped columns (with JSON container support and nested complex-property recursion).
  • Added a regression test covering a split entity with a non-JSON complex property to ensure materialization works end-to-end.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/EFCore.Relational.Specification.Tests/Query/AdHocComplexTypeQueryRelationalTestBase.cs Adds regression test Complex_property_on_split_entity for split-entity materialization with a non-JSON complex property.
src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.CreateSelect.cs Fixes table resolution for complex properties under entity splitting by choosing a table based on mapped columns instead of Single() query mapping.

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.

Entity splitting with Complex Property throws InvalidOperationException

3 participants