From 3b300c1042013d0aa2191e9394fb312d7ff6a0ff Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Wed, 29 Sep 2021 23:01:54 -0700 Subject: [PATCH] [6.0] RevEng: Initialize skip collection navigations in ctor (#26212) * RevEng: Initialize skip collection navigations in ctor Resolves #26206 --- .../Internal/CSharpEntityTypeGenerator.cs | 6 +++- .../Internal/CSharpEntityTypeGeneratorTest.cs | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs index 7086d480414..a24dc987f85 100644 --- a/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs +++ b/src/EFCore.Design/Scaffolding/Internal/CSharpEntityTypeGenerator.cs @@ -242,7 +242,11 @@ protected virtual void GenerateConstructor(IEntityType entityType) { Check.NotNull(entityType, nameof(entityType)); - var collectionNavigations = entityType.GetNavigations().Where(n => n.IsCollection).ToList(); + var collectionNavigations = entityType.GetDeclaredNavigations() + .Cast() + .Concat(entityType.GetDeclaredSkipNavigations()) + .Where(n => n.IsCollection) + .ToList(); if (collectionNavigations.Count > 0) { diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs index a9b0453cfa5..5d0223c92ed 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs @@ -2123,6 +2123,11 @@ namespace TestNamespace { public partial class Blog { + public Blog() + { + Posts = new HashSet(); + } + public int Id { get; set; } public virtual ICollection Posts { get; set; } @@ -2138,6 +2143,11 @@ namespace TestNamespace { public partial class Post { + public Post() + { + Blogs = new HashSet(); + } + public int Id { get; set; } public virtual ICollection Blogs { get; set; } @@ -2258,6 +2268,11 @@ namespace TestNamespace { public partial class Blog { + public Blog() + { + Posts = new HashSet(); + } + public int Id { get; set; } public virtual ICollection Posts { get; set; } @@ -2273,6 +2288,11 @@ namespace TestNamespace { public partial class Post { + public Post() + { + Blogs = new HashSet(); + } + public string Id { get; set; } public virtual ICollection Blogs { get; set; } @@ -2401,6 +2421,11 @@ namespace TestNamespace { public partial class Blog { + public Blog() + { + Posts = new HashSet(); + } + [Key] public int Id { get; set; } @@ -2422,6 +2447,11 @@ namespace TestNamespace { public partial class Post { + public Post() + { + Blogs = new HashSet(); + } + [Key] public int Id { get; set; }