Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework: mix table per type and table per hierarchy

I have two tables in my database:

  • BaseEntity
  • Fund

The "Fund" entity inherits from "BaseEtity" with "table per type".

In my business model I have different types of "Fund":

  • Head-Fund
  • Direct-Investment-Fund
  • etc.

I would like to have different entities for those types with "table per hierarchy", meaning that I still only have one "Fund" table with a type-discriminator column.

Is there a way to have "table per hierarchy" on an entity that derives from a base class with "table per type"?

like image 369
SolarX Avatar asked Mar 03 '11 10:03

SolarX


1 Answers

Yes, it is possible - I have had this working in EF4 for some time now.

Define EntityA and map to TableA

Define EntityB: EntityA and map to TableB

Define EntityC: EntityA and map to TableC

Define EntityD: EntityC and map to TableC
    with condition on a column from table C

Define EntityE: EntityC and map to TableC
    with a different condition on a column from table C
like image 82
Danny Varod Avatar answered Sep 24 '22 01:09

Danny Varod