Skip to content

Commit ef3d993

Browse files
[release/10.0] Fix ComplexProperty treated as nullable after update from EF Core 9.0 to 10.0 (#38045)
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
1 parent 8695aef commit ef3d993

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ private void ProcessComplexProperties(IReadOnlyTypeBase typeBase, string version
129129

130130
private static void UpdateComplexPropertyNullability(IMutableComplexProperty complexProperty, string version)
131131
{
132-
if ((version.StartsWith("8.", StringComparison.Ordinal)
133-
|| version.StartsWith("9.", StringComparison.Ordinal))
134-
&& !complexProperty.ClrType.IsNullableType())
132+
if (version.StartsWith("8.", StringComparison.Ordinal)
133+
|| version.StartsWith("9.", StringComparison.Ordinal))
135134
{
136135
complexProperty.IsNullable = false;
137136
}

test/EFCore.Design.Tests/Migrations/Design/SnapshotModelProcessorTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,42 @@ public void Updates_nested_complex_property_nullability_for_pre_10_snapshots()
293293
Assert.Empty(reporter.Messages);
294294
}
295295

296+
[ConditionalFact]
297+
public void Updates_property_bag_complex_property_nullability_for_pre_10_snapshots()
298+
{
299+
var builder = new ModelBuilder();
300+
var model = builder.Model;
301+
((Model)model).SetProductVersion("9.0.0");
302+
303+
builder.Entity(
304+
"TestEntity", b =>
305+
{
306+
b.Property<int>("Id");
307+
b.HasKey("Id");
308+
309+
b.ComplexProperty(typeof(Dictionary<string, object>), "Value", "TestEntity.Value#StructValue", b1 =>
310+
{
311+
b1.Property<int>("Value");
312+
});
313+
});
314+
315+
var entityType = model.GetEntityTypes().Single();
316+
var complexProperty = entityType.GetComplexProperties().Single();
317+
Assert.Equal(typeof(Dictionary<string, object>), complexProperty.ClrType);
318+
319+
var complexPropertyInternal = (ComplexProperty)complexProperty;
320+
Assert.Null(complexPropertyInternal.GetIsNullableConfigurationSource());
321+
Assert.True(complexProperty.IsNullable);
322+
323+
var reporter = new TestOperationReporter();
324+
var processor = new SnapshotModelProcessor(reporter, DummyModelRuntimeInitializer.Instance);
325+
processor.Process(model);
326+
327+
Assert.NotNull(complexPropertyInternal.GetIsNullableConfigurationSource());
328+
Assert.False(complexProperty.IsNullable);
329+
Assert.Empty(reporter.Messages);
330+
}
331+
296332
private static void AssertSameSnapshot(Type snapshotType, DbContext context)
297333
{
298334
var differ = context.GetService<IMigrationsModelDiffer>();

0 commit comments

Comments
 (0)