Fix redundant (string)null schema argument in ToTable snapshot generation#38424
Open
Copilot wants to merge 4 commits into
Open
Fix redundant (string)null schema argument in ToTable snapshot generation#38424Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix migration removal causing changes in snapshot
Fix redundant (string)null schema argument in ToTable snapshot generation
Jun 13, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes snapshot code generation so that migrations remove (which round-trips through the model snapshot) no longer introduces redundant , (string)null schema arguments on ToTable calls when the effective default schema is already null, improving snapshot idempotence.
Changes:
- Update
CSharpSnapshotGenerator.GenerateTableMappingto only emit an explicitnullschema argument when the entity type’s default schema is non-null (i.e., whennullis an intentional override). - Add a design-time snapshot round-trip test to ensure
ToTable("X")stays stable and doesn’t becomeToTable("X", (string)null)after round-tripping. - Add/extend migrations functional coverage for converting an owned type (under a schema-qualified owner) into a regular entity while preserving the intended schema behavior across providers.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs | Avoids emitting redundant explicit-null schema arguments during snapshot generation when the default schema is already null. |
| test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs | Adds a regression test ensuring snapshots remain identical after generate → rebuild → regenerate when default schema is null. |
| test/EFCore.Relational.Specification.Tests/Migrations/MigrationsTestBase.cs | Adds a provider-agnostic migration scenario covering owned-to-regular conversion with schema interplay and snapshot round-tripping. |
| test/EFCore.Sqlite.FunctionalTests/Migrations/MigrationsSqliteTest.cs | Adds provider-specific SQL assertions for the new owned-to-regular conversion scenario on SQLite. |
| test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs | Adds an override for the new scenario, but currently lacks SQL assertions (see comment). |
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #26067
Removing a migration rewrites the model snapshot, appending a redundant
(string)nullschema argument to everyToTablecall, leaving the snapshot with spurious uncommitted changes.Root cause
ToTable("X")always records a nullSchemaannotation. When the snapshot is round-tripped — which is whatmigrations removedoes, rebuilding the model from the snapshot —CSharpSnapshotGenerator.GenerateTableMappingre-emitted that null as, (string)null, even when the entity's default schema was alreadynull(making the argument redundant). Themigrations addpath uses the live model, where a table-name-by-convention carries no schema annotation, which is why onlyremovereproduced it.Changes
CSharpSnapshotGenerator.GenerateTableMapping: emit the explicit null schema only whenentityType.GetDefaultSchema() != null, so the argument is kept only when meaningful (overriding an inherited non-null schema, e.g. an owned entity under a schema-qualified owner) and dropped when redundant. Snapshot generation becomes idempotent.ToTable_with_default_null_schema_is_not_changed_on_snapshot_round_trip(CSharpMigrationsGeneratorTest) — asserts the snapshot is stable across generate → rebuild → regenerate.Convert_owned_entity_with_no_schema_to_regular_entity(MigrationsTestBase) — covers the owned-entity-under-schema case where(string)nullis required; asserter is order-independent and guards schema checks behindAssertSchemaNames(SQLite has no schema support and orders tables differently). SQLite and SQL Server overrides included.