Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement table-per-concrete-type strategy using entity framework

I'm mapping a set of tables that share a common set of fields:

alt text

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

like image 776
SDReyes Avatar asked Mar 15 '10 16:03

SDReyes


People also ask

What is table-Per-hierarchy in Entity Framework?

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.

What is TPH in Entity Framework?

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.

When would you use EF6 vs EF core?

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.


1 Answers

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 : )

like image 189
SDReyes Avatar answered Sep 30 '22 00:09

SDReyes