Skip to content

Fix shared type entity type name generation in model snapshot#38611

Merged
AndriySvyryd merged 1 commit into
mainfrom
Issue36180
Jul 16, 2026
Merged

Fix shared type entity type name generation in model snapshot#38611
AndriySvyryd merged 1 commit into
mainfrom
Issue36180

Conversation

@AndriySvyryd

Copy link
Copy Markdown
Member

Fixes #36180

Copilot AI review requested due to automatic review settings July 11, 2026 03:48
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner July 11, 2026 03:48
@AndriySvyryd
AndriySvyryd removed the request for review from a team July 11, 2026 03:48

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 snapshot generation for owned entity types with shared CLR types so that regenerating a model snapshot from a model that was itself built from a snapshot (e.g., during Remove-Migration) doesn’t produce corrupted owned type names in HasForeignKey(...) calls (Issue #36180).

Changes:

  • Adjust CSharpSnapshotGenerator.GetFullName to better normalize owned entity type names when HasSharedClrType is true (including handling names derived from ShortName()).
  • Add a regression test covering an owned collection containing a one-to-one reference, verifying snapshot round-tripping stability and successful compilation.

Reviewed changes

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

File Description
test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs Adds a regression test to ensure snapshot regeneration doesn’t corrupt owned type names for one-to-one relationships inside owned collections.
src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs Updates owned entity type name normalization logic for shared CLR types to prevent duplicated/incorrect owned type names in generated snapshots.

@AndriySvyryd
AndriySvyryd requested a review from cincuranet July 13, 2026 18:03
@AndriySvyryd AndriySvyryd changed the title Fix shared type entity type name generattion in model snapshot Fix shared type entity type name generation in model snapshot Jul 13, 2026
@AndriySvyryd
AndriySvyryd merged commit e1ce860 into main Jul 16, 2026
18 checks passed
@AndriySvyryd
AndriySvyryd deleted the Issue36180 branch July 16, 2026 17:44
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 17, 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.

Remove-Migration is corrupting the DbContextModelSnapshot

3 participants