EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

Specifying a HasDescrinimator in the EntityTypeConfiguration

Open nick5454 opened this issue 3 years ago • 4 comments

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 avatar May 20 '21 20:05 nick5454

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

nick5454 avatar May 20 '21 20:05 nick5454

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.

sjh37 avatar May 21 '21 10:05 sjh37

@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?

nick5454 avatar May 24 '21 12:05 nick5454

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

sjh37 avatar May 25 '21 14:05 sjh37