I'm mapping a set of tables that share a common set of fields:
So as you can see I'm using a table-per-concrete-type strategy to map the inheritance.
But...
I have not could to relate them to an abstract type containing these common properties.
It's possible to do it using EF?
BONUS: The only non documented Entity Data Model Mapping Scenario
is Table-per-concrete-type inheritance
http://msdn.microsoft.com/en-us/library/cc716779.aspx : P
Table-per-hierarchy and discriminator configuration. By default, EF maps the inheritance using the table-per-hierarchy (TPH) pattern. TPH uses a single table to store the data for all types in the hierarchy, and a discriminator column is used to identify which type each row represents.
In this article This step-by-step walkthrough shows how to implement table-per-hierarchy (TPH) inheritance in your conceptual model with the Entity Framework Designer (EF Designer). TPH inheritance uses one database table to maintain data for all of the entity types in an inheritance hierarchy.
Keep using EF6 if the data access code is stable and not likely to evolve or need new features. Port to EF Core if the data access code is evolving or if the app needs new features only available in EF Core. Porting to EF Core is also often done for performance.
Finally I created an interface 'Iggy' that contained the accessors to the common properties:
public Interface Iggy
{
string modifiedBy { get; set; }
DateTime modifiedDate { get; set; }
}
and used partial classes to implement it in the domain classes
public partial class Al:Iggy{}
public partial class Ben:Iggy{}
public partial class Carl:Iggy{}
C# is really very handy, and although I would liked to do it using a entity-framework feature, partials work like a charm : )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With