Is it possible to define Inheritance Mapping and a Discriminator Property using a BD first approach.
I use the EDMX diagram to define the mapping of tables to object.
I have a DomainEntity Table that contains all my domain entities and they are descriminated by TypeID that is mapped to a DomainEntityTypes table.
If i had full control i would design the mapping this way:
- Define an abstarct class DomainEntity
- Inherit from the DomainEntity calss to creat concrete entities
- Use the Inheritance Mapping Annotation and the IsDiscriminator Annotation over the TypeID
- Use an enum to define all possible types (and i wonder what the types table is for from that point)
Could all this be defined in the EDMX file somehow ? or do i need to stop using auto generation and continue with manual mappings?
There is no “auto-generation” of inheritance mapping. When you use database first you simply load tables to your model and it will create entities with relations. Now if you want to have inheritance you must modify the mapping from the designer. Here is a nice description how to set up TPH inheritance in the designer.