Skip to content

Place complex property columns in CLR property order when creating tables - #39163

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
tunahanaliozturk:fix/31259-complex-column-order
Oct 8, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
tunahanaliozturk:fix/31259-complex-column-order

Conversation

@tunahanaliozturk

Copy link
Copy Markdown
Contributor

Fixes #31259

When generating a CreateTable operation, columns that come from complex properties were always added at the end of the table and sorted by name. Owned types and table-split entities already have their columns placed where the navigation sits in the CLR type; complex properties now get the same treatment. The columns of a complex property, including nested complex properties, are placed at the position of that property in the CLR type, in the declaration order of the complex type. Complex properties without a CLR property still go last, and explicit column order still wins.

Adds the test from the issue plus a nested complex type case, and updates the existing migration tests and SQL baselines whose expected column order changes (only the order changes).

Copilot AI balanced review requested due to automatic review settings October 4, 2026 21:59
@tunahanaliozturk
tunahanaliozturk requested a review from a team as a code owner October 4, 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.

Copilot review overview

🟢 Approval recommended

The implementation is localized, recursively handles nested complex properties, preserves explicit ordering, and has appropriate regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Updates migrations table creation to order complex-property columns according to CLR declaration order, matching owned and table-split entities.

Changes:

  • Recursively integrates complex properties into column sorting.
  • Adds direct and nested complex-property ordering tests.
  • Updates relational assertions and provider SQL baselines.
File Description
src/​EFCore.Relational/​Migrations/​Internal/​MigrationsModelDiffer.cs Adds recursive complex-property ordering.
test/​EFCore.Relational.Tests/​Migrations/​Internal/​MigrationsModelDifferTest.cs Tests direct and nested ordering.
test/​EFCore.Relational.Specification.Tests/​Migrations/​MigrationsTestBase.cs Updates shared ordering expectations.
test/​EFCore.SqlServer.FunctionalTests/​Migrations/​MigrationsSqlServerTest.cs Updates SQL Server baselines.
test/​EFCore.Sqlite.FunctionalTests/​Migrations/​MigrationsSqliteTest.cs Updates SQLite baselines.

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

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd enabled auto-merge (squash) October 8, 2026 00:07
@AndriySvyryd
AndriySvyryd merged commit ff0d552 into dotnet:main Oct 8, 2026
20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrations: Complex property order incorrect in CreateTable

3 participants