diff --git a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs index 9938ce572ea..04a6940a970 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs @@ -565,11 +565,17 @@ protected virtual void GenerateComplexProperty( var complexType = complexProperty.ComplexType; var complexTypeBuilderName = GenerateNestedBuilderName(builderName); + var propertyType = Code.Reference(Model.DefaultPropertyBagType); + if (complexProperty.IsCollection) + { + propertyType = $"List<{propertyType}>"; + } + stringBuilder .AppendLine() .Append(builderName) .Append(complexProperty.IsCollection ? ".ComplexCollection(" : ".ComplexProperty(") - .Append($"typeof({Code.Reference(Model.DefaultPropertyBagType)}), ") + .Append($"typeof({propertyType}), ") .Append($"{Code.Literal(complexProperty.Name)}, {Code.Literal(complexType.Name)}, ") .Append(complexTypeBuilderName) .AppendLine(" =>"); diff --git a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs index dc8c917d64a..53ee02df81c 100644 --- a/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs +++ b/test/EFCore.Design.Tests/Migrations/Design/CSharpMigrationsGeneratorTest.ModelSnapshot.cs @@ -6201,7 +6201,7 @@ public virtual void Complex_types_mapped_to_json_are_stored_in_snapshot() { b2.Property("Id"); - b2.ComplexCollection(typeof(Dictionary), "Properties", "Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGeneratorTest+EntityWithOneProperty.EntityWithTwoProperties#EntityWithTwoProperties.EntityWithStringKey#EntityWithStringKey.Properties#EntityWithStringProperty", b3 => + b2.ComplexCollection(typeof(List>), "Properties", "Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGeneratorTest+EntityWithOneProperty.EntityWithTwoProperties#EntityWithTwoProperties.EntityWithStringKey#EntityWithStringKey.Properties#EntityWithStringProperty", b3 => { b3.Property("Id"); @@ -6256,6 +6256,7 @@ public virtual void Complex_types_mapped_to_json_are_stored_in_snapshot() entityWithStringKeyComplexType.FindComplexProperty(nameof(EntityWithStringKey.Properties)); Assert.True(propertiesComplexCollection.IsCollection); Assert.Equal("JsonProps", propertiesComplexCollection.GetJsonPropertyName()); + Assert.Equal(typeof(List>), propertiesComplexCollection.ClrType); }); #endregion