Skip to content

Commit 4c6574a

Browse files
committed
#793 Do not use builder.HasKey on derived types where the PK columns are hidden. Thanks to Måns Tånneryd.
1 parent 1412d81 commit 4c6574a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.v3.ttinclude

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6274,6 +6274,9 @@
62746274
if (isEfCore3Plus && t.IsView && !t.HasPrimaryKey)
62756275
return "builder.HasNoKey();";
62766276

6277+
if (t.PrimaryKeys.All(k => k.Hidden))
6278+
return string.Empty;
6279+
62776280
var defaultKey = $"builder.HasKey({t.PrimaryKeyNameHumanCase()})";
62786281
if (t.Indexes == null || !t.Indexes.Any())
62796282
return defaultKey + ";";

Generator/Generators/GeneratorEfCore.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ public override string PrimaryKeyModelBuilder(Table t)
172172
if (isEfCore3Plus && t.IsView && !t.HasPrimaryKey)
173173
return "builder.HasNoKey();";
174174

175+
if (t.PrimaryKeys.All(k => k.Hidden))
176+
return string.Empty;
177+
175178
var defaultKey = $"builder.HasKey({t.PrimaryKeyNameHumanCase()})";
176179
if (t.Indexes == null || !t.Indexes.Any())
177180
return defaultKey + ";";

0 commit comments

Comments
 (0)