Closed jdanielpa closed 1 year ago
Just change T4 line
var key = EntityType.FindPrimaryKey();
if (key != null)
to
var key = EntityType.FindPrimaryKey();
if (key != null && (EntityType.BaseType == null || key.Properties.Any(o=> o.DeclaringEntityType == EntityType)))
I've applied the same change to my code base v1.2.14
Note, I can now scaffold and run your context. It all appears to work fine on v1.2.14
I changed the line in my template to:
var key = entityType.FindPrimaryKey();
if (key != null && (EntityType.BaseType == null || key.Properties.Any(o=> o.DeclaringEntityType == EntityType)))
but I get an error scaffolding:
DbContext rule file written to OptiCAMEntities-rules.json Updated OptiCamEntities-rules.json in 32ms CodeTemplates\EFCore\DbContext.t4(131,29) : error CS0103: The name 'EntityType' does not exist in the current context
CodeTemplates\EFCore\DbContext.t4(131,108) : error CS0103: The name 'EntityType' does not exist in the current context
Any ideas?
Never mind - typo! That fixed it.
FYI, one more adjustment made today (v1.2.15) for an issue affecting scaffolding with inheritance. just in case you hit an exception.
I cannot figure out how to remove the HasKey line from OnModelCreating for classes that inherit. Here is an example:
ArcAutoRadius inherits BaseEntryExit. Scaffolding still adds the entity.HasKey line which then throws an error on calls to the database. If I comment out the entity.HasKey line then the calls to the database work.
Can you tell me if there is a way to remove the entity.HasKey line using the templates?
Thanks!