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
711 stars 227 forks source link

Specifying a HasDescrinimator in the EntityTypeConfiguration #690

Open nick5454 opened 3 years ago

nick5454 commented 3 years ago

We moved the EF from CodeFirstDatabase to your POCO Generator.

One issue we have left is how EF creates the "HasDescriminator" when the code has say this

Table: Address Columns: AddressId, Addr1, Addr2, City, State, Zip, Descriminator

Classes: BusinessAddress : Address HomeAddress : Address

How Ef has defined inside the Designer

modelBuilder.Entity("BusinessAddress", b =>
{
    b.HasBaseType("Address");
    b.HasDiscriminator().HasValue("BusinessAddress");
    b.HasData(new ...

Is the discriminator only used EF and I can remove it or is there a way to get the Generator to build Discriminator columns based on extended table classes like the example above?

nick5454 commented 3 years ago

It looks like the hardest part is detect if the table has a "table base class" and if so then add the HasDiscriminator column

sjh37 commented 3 years ago

I've thought about seeing if the generator can accurately determine base class columns (quite difficult) and discriminator columns (easier). Currently the generator does not use the .HasDiscriminator() and outputs the tables are they are in the database. So everything will work fine, but probably not exactly how you wanted it. It's something I would like to get added and working in the future. It will have to be a Settings.UseDiscriminators boolean setting so as not to break existing code when it eventually gets implemented.

nick5454 commented 3 years ago

@sjh37 I would think maybe adding a DiscrimatorAttribute to your package and we can decorate discrimators that way. If the table is marked as one then we can inject the discriminator code.

Thoughts?

sjh37 commented 3 years ago

That would be the other way to do it. Let the user decide which tables & columns to use .HasDiscriminator() for.