Skip to content

Fix seed data diffing when primary key column count changes - #38824

Open
AhmedSadek10 wants to merge 2 commits into
dotnet:mainfrom
AhmedSadek10:issue-35116-seed-data-key-expansion
Open

Fix seed data diffing when primary key column count changes#38824
AhmedSadek10 wants to merge 2 commits into
dotnet:mainfrom
AhmedSadek10:issue-35116-seed-data-key-expansion

Conversation

@AhmedSadek10

Copy link
Copy Markdown
  • Check primary key column counts before comparing columns
  • Add a test for expanding a primary key with seed data

Fixes #35116

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

- Check primary key column counts before comparing columns
- Add a test for expanding a primary key with seed data

Fixes dotnet#35116
@AhmedSadek10
AhmedSadek10 requested a review from a team as a code owner August 17, 2026 23:37
@AndriySvyryd
AndriySvyryd requested a lite review from Copilot August 17, 2026 23:40
@AndriySvyryd AndriySvyryd self-assigned this Aug 17, 2026
@AndriySvyryd AndriySvyryd added this to the 12.0.0 milestone Aug 17, 2026

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 migration scaffolding crash when diffing seed data for a table whose primary key column count changes between source and target models, by short-circuiting key mapping before per-column comparison.

Changes:

  • In MigrationsModelDiffer.DiffData, check primary key column counts before iterating/comparing key columns to avoid out-of-range indexing.
  • Add a regression test covering expanding a primary key when seed data is present.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs Adds a regression test for expanding a primary key with seed data.
src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs Prevents invalid key-column mapping when PK column counts differ during seed diffing.

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

@AhmedSadek10
AhmedSadek10 force-pushed the issue-35116-seed-data-key-expansion branch from 5bbae59 to c4d2fe2 Compare August 18, 2026 00:04
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.

ArgumentOutOfRangeException when adding a migration that expands the primary key of a table with seed data

3 participants