From 0998c5943478a98dae6f5276f3d8242d7fd31e1b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 00:46:32 +0000 Subject: [PATCH 1/9] Initial plan From cdb0442ad5d8af2411ecaf578457c2ff4c2f52a4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 00:56:56 +0000 Subject: [PATCH 2/9] Add latest migration ID to model snapshot Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../Design/CSharpMigrationsGenerator.cs | 23 +++++++- .../Design/IMigrationsCodeGenerator.cs | 4 +- .../Design/MigrationsCodeGenerator.cs | 4 +- .../Migrations/Design/MigrationsScaffolder.cs | 8 ++- ...rpMigrationsGeneratorTest.ModelSnapshot.cs | 55 +++++++++++++++++++ 5 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs index 0dc7d93a83e..4f0b4c10d5b 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs @@ -240,12 +240,14 @@ public override string GenerateMetadata( /// The model snapshot's type. /// The model snapshot's name. /// The model. + /// The ID of the latest migration that has been applied to the model. /// The model snapshot code. public override string GenerateSnapshot( string? modelSnapshotNamespace, Type contextType, string modelSnapshotName, - IModel model) + IModel model, + string? latestMigrationId = null) { var builder = new IndentedStringBuilder(); AppendAutoGeneratedTag(builder); @@ -290,7 +292,24 @@ public override string GenerateSnapshot( { builder .AppendLine("protected override void BuildModel(ModelBuilder modelBuilder)") - .AppendLine("{") + .AppendLine("{"); + + if (!string.IsNullOrEmpty(latestMigrationId)) + { + builder + .IncrementIndent() + .IncrementIndent() + .IncrementIndent() + .Append("// LatestMigrationId = ").AppendLine(Code.Literal(latestMigrationId)) + .AppendLine("// If you encounter a merge conflict in the line above, it means you need to") + .AppendLine("// discard one of the migration branches and recreate its migrations on top of") + .AppendLine("// the other branch. See https://aka.ms/efcore-docs-merge-conflicts for more info.") + .DecrementIndent() + .DecrementIndent() + .DecrementIndent(); + } + + builder .DecrementIndent() .DecrementIndent() .AppendLine("#pragma warning disable 612, 618") diff --git a/src/EFCore.Design/Migrations/Design/IMigrationsCodeGenerator.cs b/src/EFCore.Design/Migrations/Design/IMigrationsCodeGenerator.cs index 281a288204e..9b37b35907d 100644 --- a/src/EFCore.Design/Migrations/Design/IMigrationsCodeGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/IMigrationsCodeGenerator.cs @@ -49,12 +49,14 @@ string GenerateMigration( /// The model snapshot's type. /// The model snapshot's name. /// The model. + /// The ID of the latest migration that has been applied to the model. /// The model snapshot code. string GenerateSnapshot( string? modelSnapshotNamespace, Type contextType, string modelSnapshotName, - IModel model); + IModel model, + string? latestMigrationId = null); /// /// Gets the file extension code files should use. diff --git a/src/EFCore.Design/Migrations/Design/MigrationsCodeGenerator.cs b/src/EFCore.Design/Migrations/Design/MigrationsCodeGenerator.cs index 16c7dbb5917..fd50ed051a5 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsCodeGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsCodeGenerator.cs @@ -76,12 +76,14 @@ public abstract string GenerateMetadata( /// The model snapshot's type. /// The model snapshot's name. /// The model. + /// The ID of the latest migration that has been applied to the model. /// The model snapshot code. public abstract string GenerateSnapshot( string? modelSnapshotNamespace, Type contextType, string modelSnapshotName, - IModel model); + IModel model, + string? latestMigrationId = null); /// /// Gets the namespaces required for a list of objects. diff --git a/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs b/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs index ac60a7ff67e..7698372b3a1 100644 --- a/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs +++ b/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs @@ -187,7 +187,8 @@ public virtual ScaffoldedMigration ScaffoldMigration( modelSnapshotNamespace, _contextType, modelSnapshotName, - Dependencies.Model); + Dependencies.Model, + migrationId); return new ScaffoldedMigration( codeGenerator.FileExtension, @@ -346,6 +347,8 @@ public virtual MigrationFiles RemoveMigration( } } + var latestMigrationId = migrations.Count > 1 ? migrations[^2].GetId() : null; + var modelSnapshotName = modelSnapshot.GetType().Name; var modelSnapshotFileName = modelSnapshotName + codeGenerator.FileExtension; var modelSnapshotFile = TryGetProjectFile(projectDir, modelSnapshotFileName); @@ -378,7 +381,8 @@ public virtual MigrationFiles RemoveMigration( modelSnapshotNamespace, _contextType, modelSnapshotName, - model); + model, + latestMigrationId); modelSnapshotFile ??= Path.Combine( GetDirectory(projectDir, null, GetSubNamespace(rootNamespace, modelSnapshotNamespace)), diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs index d4ac447c79f..d2d496c0490 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs @@ -122,6 +122,61 @@ protected override void BuildModel(ModelBuilder modelBuilder) Assert.Equal(2, snapshot.Model.GetEntityTypes().Count()); } + [ConditionalFact] + public void Snapshot_with_migration_id() + { + var generator = CreateMigrationsCodeGenerator(); + + var modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder(); + modelBuilder.Entity(x => + { + x.Property(e => e.Id); + }); + + var finalizedModel = modelBuilder.FinalizeModel(designTime: true); + + var modelSnapshotCode = generator.GenerateSnapshot( + "MyNamespace", + typeof(MyContext), + "MySnapshot", + finalizedModel, + "20240101120000_InitialCreate"); + + Assert.Contains("// LatestMigrationId = \"20240101120000_InitialCreate\"", modelSnapshotCode); + Assert.Contains("// If you encounter a merge conflict in the line above, it means you need to", modelSnapshotCode); + Assert.Contains("// discard one of the migration branches and recreate its migrations on top of", modelSnapshotCode); + Assert.Contains("// the other branch. See https://aka.ms/efcore-docs-merge-conflicts for more info.", modelSnapshotCode); + + var snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot", typeof(MyContext)); + Assert.NotNull(snapshot.Model); + } + + [ConditionalFact] + public void Snapshot_without_migration_id() + { + var generator = CreateMigrationsCodeGenerator(); + + var modelBuilder = FakeRelationalTestHelpers.Instance.CreateConventionBuilder(); + modelBuilder.Entity(x => + { + x.Property(e => e.Id); + }); + + var finalizedModel = modelBuilder.FinalizeModel(designTime: true); + + var modelSnapshotCode = generator.GenerateSnapshot( + "MyNamespace", + typeof(MyContext), + "MySnapshot", + finalizedModel); + + Assert.DoesNotContain("LatestMigrationId", modelSnapshotCode); + Assert.DoesNotContain("merge conflict", modelSnapshotCode); + + var snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot", typeof(MyContext)); + Assert.NotNull(snapshot.Model); + } + [ConditionalFact] public void Snapshot_default_values_are_round_tripped() { From e5ebe679f59df4488907933c1b579d8f958338c2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 01:04:07 +0000 Subject: [PATCH 3/9] Fix indentation for migration ID comment in snapshot Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../Migrations/Design/CSharpMigrationsGenerator.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs index 4f0b4c10d5b..a1d3d630c9c 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs @@ -292,26 +292,21 @@ public override string GenerateSnapshot( { builder .AppendLine("protected override void BuildModel(ModelBuilder modelBuilder)") - .AppendLine("{"); + .AppendLine("{") + .DecrementIndent() + .DecrementIndent(); if (!string.IsNullOrEmpty(latestMigrationId)) { builder - .IncrementIndent() - .IncrementIndent() - .IncrementIndent() .Append("// LatestMigrationId = ").AppendLine(Code.Literal(latestMigrationId)) .AppendLine("// If you encounter a merge conflict in the line above, it means you need to") .AppendLine("// discard one of the migration branches and recreate its migrations on top of") .AppendLine("// the other branch. See https://aka.ms/efcore-docs-merge-conflicts for more info.") - .DecrementIndent() - .DecrementIndent() - .DecrementIndent(); + .AppendLine(); } builder - .DecrementIndent() - .DecrementIndent() .AppendLine("#pragma warning disable 612, 618") .IncrementIndent() .IncrementIndent(); From b12b33f85788a6977c7c0e589e5840392f4d1bf4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 01:08:25 +0000 Subject: [PATCH 4/9] Remove trailing whitespace Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../Migrations/Design/CSharpMigrationsGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs index a1d3d630c9c..3238783fedf 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs @@ -295,7 +295,7 @@ public override string GenerateSnapshot( .AppendLine("{") .DecrementIndent() .DecrementIndent(); - + if (!string.IsNullOrEmpty(latestMigrationId)) { builder From a57ebaa33191747d08f4a5dfef1e8cef5f3027df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 01:53:46 +0000 Subject: [PATCH 5/9] Change migration ID from comment to model annotation Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../Migrations/Design/CSharpMigrationsGenerator.cs | 6 +++--- .../Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs index 3238783fedf..7186f38fb5e 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs @@ -299,10 +299,10 @@ public override string GenerateSnapshot( if (!string.IsNullOrEmpty(latestMigrationId)) { builder - .Append("// LatestMigrationId = ").AppendLine(Code.Literal(latestMigrationId)) - .AppendLine("// If you encounter a merge conflict in the line above, it means you need to") + .AppendLine("// If you encounter a merge conflict in the line below, it means you need to") .AppendLine("// discard one of the migration branches and recreate its migrations on top of") - .AppendLine("// the other branch. See https://aka.ms/efcore-docs-merge-conflicts for more info.") + .AppendLine("// the other branch. See https://aka.ms/efcore-docs-migrations-conflicts for more info.") + .Append("modelBuilder.HasAnnotation(\"LatestMigrationId\", ").Append(Code.Literal(latestMigrationId)).AppendLine(");") .AppendLine(); } diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs index d2d496c0490..efd784d7b85 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs @@ -142,13 +142,14 @@ public void Snapshot_with_migration_id() finalizedModel, "20240101120000_InitialCreate"); - Assert.Contains("// LatestMigrationId = \"20240101120000_InitialCreate\"", modelSnapshotCode); - Assert.Contains("// If you encounter a merge conflict in the line above, it means you need to", modelSnapshotCode); + Assert.Contains("modelBuilder.HasAnnotation(\"LatestMigrationId\", \"20240101120000_InitialCreate\");", modelSnapshotCode); + Assert.Contains("// If you encounter a merge conflict in the line below, it means you need to", modelSnapshotCode); Assert.Contains("// discard one of the migration branches and recreate its migrations on top of", modelSnapshotCode); - Assert.Contains("// the other branch. See https://aka.ms/efcore-docs-merge-conflicts for more info.", modelSnapshotCode); + Assert.Contains("// the other branch. See https://aka.ms/efcore-docs-migrations-conflicts for more info.", modelSnapshotCode); var snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot", typeof(MyContext)); Assert.NotNull(snapshot.Model); + Assert.Equal("20240101120000_InitialCreate", snapshot.Model.FindAnnotation("LatestMigrationId")?.Value); } [ConditionalFact] From bc634661531b8817dd88b2d0e3235ffa2d6651e5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 02:09:38 +0000 Subject: [PATCH 6/9] Change migration ID to a property on the ModelSnapshot class Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- .../Migrations/Design/CSharpMigrationsGenerator.cs | 12 +++++------- .../Infrastructure/ModelSnapshot.cs | 9 +++++++++ .../CSharpMigrationsGeneratorTest.ModelSnapshot.cs | 5 +++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs index 7186f38fb5e..b31350895c0 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpMigrationsGenerator.cs @@ -290,23 +290,21 @@ public override string GenerateSnapshot( .AppendLine("{"); using (builder.Indent()) { - builder - .AppendLine("protected override void BuildModel(ModelBuilder modelBuilder)") - .AppendLine("{") - .DecrementIndent() - .DecrementIndent(); - if (!string.IsNullOrEmpty(latestMigrationId)) { builder .AppendLine("// If you encounter a merge conflict in the line below, it means you need to") .AppendLine("// discard one of the migration branches and recreate its migrations on top of") .AppendLine("// the other branch. See https://aka.ms/efcore-docs-migrations-conflicts for more info.") - .Append("modelBuilder.HasAnnotation(\"LatestMigrationId\", ").Append(Code.Literal(latestMigrationId)).AppendLine(");") + .Append("public override string LatestMigrationId => ").Append(Code.Literal(latestMigrationId)).AppendLine(";") .AppendLine(); } builder + .AppendLine("protected override void BuildModel(ModelBuilder modelBuilder)") + .AppendLine("{") + .DecrementIndent() + .DecrementIndent() .AppendLine("#pragma warning disable 612, 618") .IncrementIndent() .IncrementIndent(); diff --git a/src/EFCore.Relational/Infrastructure/ModelSnapshot.cs b/src/EFCore.Relational/Infrastructure/ModelSnapshot.cs index 0e13a4b4330..d19579e39be 100644 --- a/src/EFCore.Relational/Infrastructure/ModelSnapshot.cs +++ b/src/EFCore.Relational/Infrastructure/ModelSnapshot.cs @@ -28,6 +28,15 @@ private IModel CreateModel() public virtual IModel Model => _model ??= CreateModel(); + /// + /// The ID of the latest migration applied to the model when the snapshot was created. + /// + /// + /// See Database migrations for more information and examples. + /// + public virtual string? LatestMigrationId + => null; + /// /// Called lazily by to build the model snapshot /// the first time it is requested. diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs index efd784d7b85..13e0cf78c93 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs @@ -142,14 +142,14 @@ public void Snapshot_with_migration_id() finalizedModel, "20240101120000_InitialCreate"); - Assert.Contains("modelBuilder.HasAnnotation(\"LatestMigrationId\", \"20240101120000_InitialCreate\");", modelSnapshotCode); + Assert.Contains("public override string LatestMigrationId => \"20240101120000_InitialCreate\";", modelSnapshotCode); Assert.Contains("// If you encounter a merge conflict in the line below, it means you need to", modelSnapshotCode); Assert.Contains("// discard one of the migration branches and recreate its migrations on top of", modelSnapshotCode); Assert.Contains("// the other branch. See https://aka.ms/efcore-docs-migrations-conflicts for more info.", modelSnapshotCode); var snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot", typeof(MyContext)); Assert.NotNull(snapshot.Model); - Assert.Equal("20240101120000_InitialCreate", snapshot.Model.FindAnnotation("LatestMigrationId")?.Value); + Assert.Equal("20240101120000_InitialCreate", snapshot.LatestMigrationId); } [ConditionalFact] @@ -176,6 +176,7 @@ public void Snapshot_without_migration_id() var snapshot = CompileModelSnapshot(modelSnapshotCode, "MyNamespace.MySnapshot", typeof(MyContext)); Assert.NotNull(snapshot.Model); + Assert.Null(snapshot.LatestMigrationId); } [ConditionalFact] From d84b2eff40d68bfe70b27bf99e00d0291ca5e9ae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 02:30:03 +0000 Subject: [PATCH 7/9] Update documentation link in ModelSnapshot.LatestMigrationId Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- src/EFCore.Relational/Infrastructure/ModelSnapshot.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EFCore.Relational/Infrastructure/ModelSnapshot.cs b/src/EFCore.Relational/Infrastructure/ModelSnapshot.cs index d19579e39be..d98421b7c9e 100644 --- a/src/EFCore.Relational/Infrastructure/ModelSnapshot.cs +++ b/src/EFCore.Relational/Infrastructure/ModelSnapshot.cs @@ -32,7 +32,7 @@ public virtual IModel Model /// The ID of the latest migration applied to the model when the snapshot was created. /// /// - /// See Database migrations for more information and examples. + /// See Database migrations for more information and examples. /// public virtual string? LatestMigrationId => null; From 319b537f1813d169771e605d305e05d2a0c332f0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 04:34:03 +0000 Subject: [PATCH 8/9] Fix failing MigrationTests to include LatestMigrationId property Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- test/EFCore.SqlServer.HierarchyId.Tests/MigrationTests.cs | 8 ++++---- .../TestModels/Migrations/AnonymousArraySeedContext.cs | 7 ++++++- .../TestModels/Migrations/MigrationContext.cs | 2 +- .../TestModels/Migrations/TypedArraySeedContext.cs | 7 ++++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/test/EFCore.SqlServer.HierarchyId.Tests/MigrationTests.cs b/test/EFCore.SqlServer.HierarchyId.Tests/MigrationTests.cs index fdf30e40676..8513756aa09 100644 --- a/test/EFCore.SqlServer.HierarchyId.Tests/MigrationTests.cs +++ b/test/EFCore.SqlServer.HierarchyId.Tests/MigrationTests.cs @@ -15,7 +15,7 @@ public class MigrationTests { private delegate string MigrationCodeGetter(string migrationName, string rootNamespace); - private delegate string SnapshotCodeGetter(string rootNamespace); + private delegate string SnapshotCodeGetter(string rootNamespace, string migrationId); [ConditionalFact] public void Migration_and_snapshot_generate_with_typed_array() @@ -39,9 +39,6 @@ private static void ValidateMigrationAndSnapshotCode( const string migrationName = "MyMigration"; const string rootNamespace = "MyApp.Data"; - var expectedMigration = migrationCodeGetter(migrationName, rootNamespace); - var expectedSnapshot = snapshotCodeGetter(rootNamespace); - var reporter = new OperationReporter( new OperationReportHandler( m => Console.WriteLine($" error: {m}"), @@ -59,6 +56,9 @@ private static void ValidateMigrationAndSnapshotCode( .GetRequiredService() .ScaffoldMigration(migrationName, rootNamespace); + var expectedMigration = migrationCodeGetter(migrationName, rootNamespace); + var expectedSnapshot = snapshotCodeGetter(rootNamespace, migration.MigrationId); + Assert.Equal(expectedMigration, migration.MigrationCode, ignoreLineEndingDifferences: true); Assert.Equal(expectedSnapshot, migration.SnapshotCode, ignoreLineEndingDifferences: true); } diff --git a/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/AnonymousArraySeedContext.cs b/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/AnonymousArraySeedContext.cs index 9452af5c3cb..174170aa2bb 100644 --- a/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/AnonymousArraySeedContext.cs +++ b/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/AnonymousArraySeedContext.cs @@ -116,7 +116,7 @@ protected override void Down(MigrationBuilder migrationBuilder) }} "; - public override string GetExpectedSnapshotCode(string rootNamespace) + public override string GetExpectedSnapshotCode(string rootNamespace, string migrationId) => $@"// using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -131,6 +131,11 @@ namespace {rootNamespace}.Migrations [DbContext(typeof({ThisType.Name}))] partial class {ThisType.Name}ModelSnapshot : ModelSnapshot {{ + // If you encounter a merge conflict in the line below, it means you need to + // discard one of the migration branches and recreate its migrations on top of + // the other branch. See https://aka.ms/efcore-docs-migrations-conflicts for more info. + public override string LatestMigrationId => ""{migrationId}""; + protected override void BuildModel(ModelBuilder modelBuilder) {{ #pragma warning disable 612, 618 diff --git a/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/MigrationContext.cs b/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/MigrationContext.cs index 08d338de11a..c347a9cc590 100644 --- a/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/MigrationContext.cs +++ b/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/MigrationContext.cs @@ -45,5 +45,5 @@ protected void RemoveVariableModelAnnotations(ModelBuilder modelBuilder) } public abstract string GetExpectedMigrationCode(string migrationName, string rootNamespace); - public abstract string GetExpectedSnapshotCode(string rootNamespace); + public abstract string GetExpectedSnapshotCode(string rootNamespace, string migrationId); } diff --git a/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/TypedArraySeedContext.cs b/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/TypedArraySeedContext.cs index c54b9ec38b5..94edd2ca7d3 100644 --- a/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/TypedArraySeedContext.cs +++ b/test/EFCore.SqlServer.HierarchyId.Tests/TestModels/Migrations/TypedArraySeedContext.cs @@ -116,7 +116,7 @@ protected override void Down(MigrationBuilder migrationBuilder) }} "; - public override string GetExpectedSnapshotCode(string rootNamespace) + public override string GetExpectedSnapshotCode(string rootNamespace, string migrationId) => $@"// using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -131,6 +131,11 @@ namespace {rootNamespace}.Migrations [DbContext(typeof({ThisType.Name}))] partial class {ThisType.Name}ModelSnapshot : ModelSnapshot {{ + // If you encounter a merge conflict in the line below, it means you need to + // discard one of the migration branches and recreate its migrations on top of + // the other branch. See https://aka.ms/efcore-docs-migrations-conflicts for more info. + public override string LatestMigrationId => ""{migrationId}""; + protected override void BuildModel(ModelBuilder modelBuilder) {{ #pragma warning disable 612, 618 From 8a32ca7d3680005d7f97c6e9e3b4f86920a470a5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 19:11:51 +0000 Subject: [PATCH 9/9] Fix failing OperationExecutorTest snapshots to include LatestMigrationId Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com> --- test/EFCore.Design.Tests/Design/OperationExecutorTest.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/EFCore.Design.Tests/Design/OperationExecutorTest.cs b/test/EFCore.Design.Tests/Design/OperationExecutorTest.cs index 3965bf9a994..7e185a7610b 100644 --- a/test/EFCore.Design.Tests/Design/OperationExecutorTest.cs +++ b/test/EFCore.Design.Tests/Design/OperationExecutorTest.cs @@ -180,6 +180,11 @@ namespace My.Gnomespace.Data [DbContext(typeof(OperationExecutorTest.GnomeContext))] partial class GnomeContextModelSnapshot : ModelSnapshot { + // If you encounter a merge conflict in the line below, it means you need to + // discard one of the migration branches and recreate its migrations on top of + // the other branch. See https://aka.ms/efcore-docs-migrations-conflicts for more info. + public override string LatestMigrationId => "11112233445566_{{migrationName}}"; + protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618