Skip to content

Parse the identity seed as a long when generating DBCC CHECKIDENT on SQL Server - #39157

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlserver-identity-seed-long
Oct 3, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/sqlserver-identity-seed-long

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

UseIdentityColumn takes a long seed and the column definition emits it verbatim, but the seed change path in SqlServerMigrationsSqlGenerator parsed the Identity annotation with int.TryParse. Changing the seed of a bigint identity column to a value above int.MaxValue therefore produced an empty migration instead of DBCC CHECKIDENT. The seed and increment are now parsed as longs with the invariant culture, and the seed is formatted with the invariant culture too.

  • [x ] I've read the guidelines for contributing and seen the walkthrough
  • [ x] 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
  • [ x] The code builds and tests pass locally (also verified by our automated build checks)
  • [x ] Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

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

…SQL Server

UseIdentityColumn takes a long seed and the column definition emits it verbatim,
but the seed change path in SqlServerMigrationsSqlGenerator parsed the Identity
annotation with int.TryParse. Changing the seed of a bigint identity column to a
value above int.MaxValue therefore produced an empty migration instead of
DBCC CHECKIDENT. The seed and increment are now parsed as longs with the
invariant culture, and the seed is formatted with the invariant culture too.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

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

No unresolved issues were identified, and reviewers assessed it as ready for approval.

Review effort: Lite
Findings: None

What changed in this PR

Updates SQL Server migration generation to support identity seeds above int.MaxValue.

Changes:

  • Parses identity seeds and increments as invariant-culture long values.
  • Formats reseed SQL invariantly.
  • Adds generator and functional regression tests.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Migrations/​SqlServerMigrationsSqlGeneratorTest.cs Tests generated reseed SQL.
test/​EFCore.SqlServer.FunctionalTests/​Migrations/​MigrationsSqlServerTest.cs Adds end-to-end migration coverage.
src/​EFCore.SqlServer/​Migrations/​SqlServerMigrationsSqlGenerator.cs Handles long identity seeds.

💡 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 merged commit a8255c1 into dotnet:main Oct 3, 2026
20 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 5, 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.

3 participants