diff --git a/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs b/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs index a47c283c472..30b89651e13 100644 --- a/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs +++ b/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs @@ -52,7 +52,9 @@ public SnapshotModelProcessor( /// public virtual IModel? Process(IReadOnlyModel? model, bool resetVersion = false) { - if (model == null) + if (model == null + || model is not Model mutableModel + || mutableModel.IsReadOnly) { return null; } @@ -79,13 +81,10 @@ public SnapshotModelProcessor( } } - if (model is IMutableModel mutableModel) + mutableModel.RemoveAnnotation("ChangeDetector.SkipDetectChanges"); + if (resetVersion) { - mutableModel.RemoveAnnotation("ChangeDetector.SkipDetectChanges"); - if (resetVersion) - { - mutableModel.SetProductVersion(ProductInfo.GetVersion()); - } + mutableModel.SetProductVersion(ProductInfo.GetVersion()); } return _modelRuntimeInitializer.Initialize((IModel)model, designTime: true, validationLogger: null); diff --git a/test/EFCore.Design.Tests/Migrations/Design/SnapshotModelProcessorTest.cs b/test/EFCore.Design.Tests/Migrations/Design/SnapshotModelProcessorTest.cs index 6cbc70fc2d8..c7070dcc763 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/SnapshotModelProcessorTest.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/SnapshotModelProcessorTest.cs @@ -43,7 +43,8 @@ public void Updates_provider_annotations_on_model() var reporter = new TestOperationReporter(); - new SnapshotModelProcessor(reporter, DummyModelRuntimeInitializer.Instance).Process(model); + var processor = new SnapshotModelProcessor(reporter, DummyModelRuntimeInitializer.Instance); + processor.Process(model); AssertAnnotations(model); AssertAnnotations(entityType); @@ -54,6 +55,8 @@ public void Updates_provider_annotations_on_model() AssertAnnotations(nav2); AssertAnnotations(index); + Assert.Same(model, processor.Process(model)); + Assert.Empty(reporter.Messages); }