diff --git a/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs b/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs index 2fa73c9a226..c46bb2bf93b 100644 --- a/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs +++ b/src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs @@ -129,9 +129,8 @@ private void ProcessComplexProperties(IReadOnlyTypeBase typeBase, string version private static void UpdateComplexPropertyNullability(IMutableComplexProperty complexProperty, string version) { - if ((version.StartsWith("8.", StringComparison.Ordinal) - || version.StartsWith("9.", StringComparison.Ordinal)) - && !complexProperty.ClrType.IsNullableType()) + if (version.StartsWith("8.", StringComparison.Ordinal) + || version.StartsWith("9.", StringComparison.Ordinal)) { complexProperty.IsNullable = false; } diff --git a/test/EFCore.Design.Tests/Migrations/Design/SnapshotModelProcessorTest.cs b/test/EFCore.Design.Tests/Migrations/Design/SnapshotModelProcessorTest.cs index 5faa18ad8ca..a9e381ac96e 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/SnapshotModelProcessorTest.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/SnapshotModelProcessorTest.cs @@ -293,6 +293,42 @@ public void Updates_nested_complex_property_nullability_for_pre_10_snapshots() Assert.Empty(reporter.Messages); } + [ConditionalFact] + public void Updates_property_bag_complex_property_nullability_for_pre_10_snapshots() + { + var builder = new ModelBuilder(); + var model = builder.Model; + ((Model)model).SetProductVersion("9.0.0"); + + builder.Entity( + "TestEntity", b => + { + b.Property("Id"); + b.HasKey("Id"); + + b.ComplexProperty(typeof(Dictionary), "Value", "TestEntity.Value#StructValue", b1 => + { + b1.Property("Value"); + }); + }); + + var entityType = model.GetEntityTypes().Single(); + var complexProperty = entityType.GetComplexProperties().Single(); + Assert.Equal(typeof(Dictionary), complexProperty.ClrType); + + var complexPropertyInternal = (ComplexProperty)complexProperty; + Assert.Null(complexPropertyInternal.GetIsNullableConfigurationSource()); + Assert.True(complexProperty.IsNullable); + + var reporter = new TestOperationReporter(); + var processor = new SnapshotModelProcessor(reporter, DummyModelRuntimeInitializer.Instance); + processor.Process(model); + + Assert.NotNull(complexPropertyInternal.GetIsNullableConfigurationSource()); + Assert.False(complexProperty.IsNullable); + Assert.Empty(reporter.Messages); + } + private static void AssertSameSnapshot(Type snapshotType, DbContext context) { var differ = context.GetService();