0

I have a complex data model (for EF 4.1 code first) that uses composition (many 1-to-1's) to achieve benefits similar to multiple inheritance. But I have a problem to solve, hopefully with mapping.

  1. I need to reduce the number of tables (not entities) to simulate successful multiple inheritance.

  2. I cannot replace the 1-to-1 composition classes with complex types because I will use Dynamic Data as an admin back-end and DD doesn't work with complex types.

  3. Table-per-hierarchy does not seem it would help here because of the simulated multiple inheritance.

  4. Table-per-type would give way too many tables.

I think there is something called "entity splitting". And I think I basically need the opposite of it? I wonder if what I want is even possible... basically simulating complex types by mapping model components more than once.. it sounds impossible. Should I just scrap the composition approach? I could always group properties with attributes or something.

Benjamin
  • 3,134
  • 6
  • 36
  • 57

1 Answers1

2

The opposite of entity splitting is called table splitting and it is really possible but it has one big problem happening only in EF code first.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • thank you for the quick reply! If I am trying to use a single class in multiple classes (to simulate multi-inherit) how can that component class be mapped more than once (since multiple tables will need it)? For example, if type `SchedulingInfo` has 1-to-1 with type `Sale` AND `Order` AND `DonutBreak` but those 3 types should be 3 different tables. Can `SchedulingInfo` be mapped more than once to all 3 tables without splitting it? If not then I might as well flatten the model? – Benjamin Jan 10 '12 at 16:20
  • No single class can be mapped only once. The only exceptions are mapped inheritance and splitting scenarios. – Ladislav Mrnka Jan 10 '12 at 16:23
  • Ok. So if I can't use complex types in DyanmicData, then the best solution is table-per-type and repeat each property on each class that needs it? Or single inheritance? – Benjamin Jan 10 '12 at 16:43