Skip to content

Preserve model-level SQL Server HiLo sequences in snapshots - #39325

Merged
AndriySvyryd merged 1 commit into
mainfrom
roji-fix-sql-server-hilo-snapshots
Oct 20, 2026
Merged

AndriySvyryd merged 1 commit into
mainfrom
roji-fix-sql-server-hilo-snapshots

Conversation

@roji

@roji roji commented Oct 18, 2026

Copy link
Copy Markdown
Member

Fixes #39324.

Related context: npgsql/efcore.pg#3613.

When generating property-level UseHiLo, fall back to the model's sequence name and schema if the property has no corresponding annotations. This prevents snapshots from creating an extra default sequence, repeated DropSequence migrations, and false pending-model changes. Explicit property overrides and model-level code generation remain unchanged.

Regression tests cover default/custom names and schemas, property overrides, and compiled snapshot roundtrips with empty model differences. Confirmed the new tests fail before the fix.

Validation (using . ./activate.sh after bootstrapping the repository SDK/runtime):

  • dotnet test test/EFCore.SqlServer.Tests/EFCore.SqlServer.Tests.csproj -- --filter-class '*SqlServerAnnotationCodeGeneratorTest' — passed, 27 tests.
  • dotnet test test/EFCore.Design.Tests/EFCore.Design.Tests.csproj -- --filter-class '*CSharpMigrationsGeneratorTest' — passed, 171 tests.
  • 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

- Fall back to the model's HiLo sequence name and schema when generating property configuration.\n- Cover inherited sequence settings, explicit property overrides, and snapshot roundtrips.\n\nFixes #39324

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 736c05ed-1c93-423e-99fc-f6298c341738
Copilot AI balanced review requested due to automatic review settings October 18, 2026 13:15
@roji
roji requested a review from a team as a code owner October 18, 2026 13:15

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 narrow fix preserves existing overrides and model-level behavior, with focused regression coverage and no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes #39324 by preserving inherited SQL Server HiLo sequence settings in migration snapshots, preventing extra default sequences and false model differences.

Changes:

  • Falls back to model-level sequence names and schemas for property-level UseHiLo.
  • Preserves explicit property overrides and model-level generation.
  • Adds generator and snapshot-roundtrip regression coverage.
File Description
test/​EFCore.SqlServer.Tests/​Design/​Internal/​SqlServerAnnotationCodeGeneratorTest.cs Tests inherited settings and explicit overrides.
test/​EFCore.Design.Tests/​Migrations/​Design/​CSharpMigrationsGeneratorTest.ModelSnapshot.cs Tests sequence preservation through snapshot roundtrips.
src/​EFCore.SqlServer/​Design/​Internal/​SqlServerAnnotationCodeGenerator.cs Adds model-level fallback for property HiLo generation.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main 2e88827 roji-fix-sql-server-... 99866c4 +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 2e88827 roji-fix-sql-server-... 99866c4 +/-
src/EFCore.Sqli...ryRepository.cs 97% 91% -6%
src/EFCore.Rela...erExtensions.cs 96% 96% 0%
src/EFCore.SqlS...odeGenerator.cs 100% 100% 0%
src/EFCore.Anal...icSuppressor.cs 96% 96% 0%
src/EFCore.Cosm...erExtensions.cs 100% 100% 0%
src/EFCore.Cosm...nsExtensions.cs 82% 82% 0%
src/EFCore.Cosm...erExtensions.cs 46% 46% 0%
src/EFCore.Cosm...peExtensions.cs 73% 73% 0%
src/EFCore.Cosm...StreamHelper.cs 87% 87% 0%
src/Shared/NonC...yInitializer.cs 11% 12% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 18, 2026 21:36 UTC

@AndriySvyryd
AndriySvyryd merged commit abf7bd9 into main Oct 20, 2026
48 checks passed
@AndriySvyryd
AndriySvyryd deleted the roji-fix-sql-server-hilo-snapshots branch October 20, 2026 01:56
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 21, 2026
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.

SQL Server: custom model-level HiLo sequence causes repeated DropSequence migrations and pending model changes

3 participants