diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs index 7a2db72cc6b..9e43546ebf1 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs @@ -158,7 +158,7 @@ public virtual string TransformText() this.Write(this.ToStringHelper.ToStringWithCulture(targetType)); this.Write("> "); this.Write(this.ToStringHelper.ToStringWithCulture(navigation.Name)); - this.Write(" { get; } = new List<"); + this.Write(" { get; set; } = new List<"); this.Write(this.ToStringHelper.ToStringWithCulture(targetType)); this.Write(">();\r\n"); @@ -200,7 +200,7 @@ public virtual string TransformText() this.Write(this.ToStringHelper.ToStringWithCulture(skipNavigation.TargetEntityType.Name)); this.Write("> "); this.Write(this.ToStringHelper.ToStringWithCulture(skipNavigation.Name)); - this.Write(" { get; } = new List<"); + this.Write(" { get; set; } = new List<"); this.Write(this.ToStringHelper.ToStringWithCulture(skipNavigation.TargetEntityType.Name)); this.Write(">();\r\n"); diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.tt b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.tt index a0a6605d03b..fedb55bae0c 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.tt +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.tt @@ -124,7 +124,7 @@ public partial class <#= EntityType.Name #> if (navigation.IsCollection) { #> - public virtual ICollection<<#= targetType #>> <#= navigation.Name #> { get; } = new List<<#= targetType #>>(); + public virtual ICollection<<#= targetType #>> <#= navigation.Name #> { get; set; } = new List<<#= targetType #>>(); <# } else @@ -151,7 +151,7 @@ public partial class <#= EntityType.Name #> } } #> - public virtual ICollection<<#= skipNavigation.TargetEntityType.Name #>> <#= skipNavigation.Name #> { get; } = new List<<#= skipNavigation.TargetEntityType.Name #>>(); + public virtual ICollection<<#= skipNavigation.TargetEntityType.Name #>> <#= skipNavigation.Name #> { get; set; } = new List<<#= skipNavigation.TargetEntityType.Name #>>(); <# } #> diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs index b1bfd2cc0e6..fb35ad7fe87 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs @@ -935,7 +935,7 @@ public partial class Entity for (var i = 1; i <= 4; i++) { Assert.Contains( - "public virtual ICollection Entity { get; }", + "public virtual ICollection Entity { get; set; }", code.AdditionalFiles.Single(f => f.Path == $"Dependent{i}.cs").Code); } }, @@ -1414,7 +1414,7 @@ public partial class Post public virtual Person Author { get; set; } [InverseProperty(""Post"")] - public virtual ICollection Contributions { get; } = new List(); + public virtual ICollection Contributions { get; set; } = new List(); } ", code.AdditionalFiles.Single(f => f.Path == "Post.cs")); @@ -1434,7 +1434,7 @@ public partial class Person public int Id { get; set; } [InverseProperty(""Author"")] - public virtual ICollection Posts { get; } = new List(); + public virtual ICollection Posts { get; set; } = new List(); } ", code.AdditionalFiles.Single(f => f.Path == "Person.cs")); @@ -1703,7 +1703,7 @@ public partial class Color public string ColorCode { get; set; } = null!; - public virtual ICollection Cars { get; } = new List(); + public virtual ICollection Cars { get; set; } = new List(); } ", code.AdditionalFiles.Single(f => f.Path == "Color.cs")); @@ -2350,7 +2350,7 @@ public partial class Blog { public int Id { get; set; } - public virtual ICollection Posts { get; } = new List(); + public virtual ICollection Posts { get; set; } = new List(); } ", code.AdditionalFiles.Single(e => e.Path == "Blog.cs")); @@ -2365,7 +2365,7 @@ public partial class Post { public int Id { get; set; } - public virtual ICollection Blogs { get; } = new List(); + public virtual ICollection Blogs { get; set; } = new List(); } ", code.AdditionalFiles.Single(e => e.Path == "Post.cs")); @@ -2476,7 +2476,7 @@ public partial class Blog { public int Id { get; set; } - public virtual ICollection Posts { get; } = new List(); + public virtual ICollection Posts { get; set; } = new List(); } ", code.AdditionalFiles.Single(e => e.Path == "Blog.cs")); @@ -2491,7 +2491,7 @@ public partial class Post { public string Id { get; set; } - public virtual ICollection Blogs { get; } = new List(); + public virtual ICollection Blogs { get; set; } = new List(); } ", code.AdditionalFiles.Single(e => e.Path == "Post.cs")); @@ -2613,7 +2613,7 @@ public partial class Blog [ForeignKey(""BlogsId"")] [InverseProperty(""Blogs"")] - public virtual ICollection Posts { get; } = new List(); + public virtual ICollection Posts { get; set; } = new List(); } ", code.AdditionalFiles.Single(e => e.Path == "Blog.cs")); @@ -2634,7 +2634,7 @@ public partial class Post [ForeignKey(""PostsId"")] [InverseProperty(""Posts"")] - public virtual ICollection Blogs { get; } = new List(); + public virtual ICollection Blogs { get; set; } = new List(); } ", code.AdditionalFiles.Single(e => e.Path == "Post.cs")); @@ -2762,7 +2762,7 @@ public partial class Blog public int Key { get; set; } - public virtual ICollection Posts { get; } = new List(); + public virtual ICollection Posts { get; set; } = new List(); } ", code.AdditionalFiles.Single(e => e.Path == "Blog.cs")); @@ -2783,7 +2783,7 @@ public partial class Post [ForeignKey(""PostsId"")] [InverseProperty(""Posts"")] - public virtual ICollection Blogs { get; } = new List(); + public virtual ICollection Blogs { get; set; } = new List(); } ", code.AdditionalFiles.Single(e => e.Path == "Post.cs"));