sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
700 stars 230 forks source link

Table-Per-Type and .NET 7 #793

Closed mtanneryd closed 1 year ago

mtanneryd commented 1 year ago

Hi!

I'm running into some problems with TPT when generating using TemplateType.EfCore7. Is it supposed to work? I get the following result when launching the app:

InvalidOperationException: A key cannot be configured on 'ComputedCurveCategorySource' because it is a derived type. The key must be configured on the root type 'CurveCategorySource'. If you did not intend for 'CurveCategorySource' to be included in the model, ensure that it is not referenced by a DbSet property on your context, referenced in a configuration call to ModelBuilder, or referenced from a navigation on a type that is included in the model.

I'll try to create a small sample and post it later.

mtanneryd commented 1 year ago

The problem seems to be that I need to somehow NOT generate "builder.HasKey" in the Configure method of the derived class.

mtanneryd commented 1 year ago

Adding this in method PrimaryKeyModelBuilder in class GeneratorEfCore seems to do the trick.

if (t.PrimaryKeys.All(k=>k.Hidden)) return "";

sjh37 commented 1 year ago

Thanks Måns, this will be in the next release.

sjh37 commented 1 year ago

Released in v3.8.1