Loading ...

Inheritance Strategy In Code First

Hello everybody,

today I want to write about reflecting hierarchy of classes in db with help of code-first.

There are three types: 

  1. Table per Hierarchy
  2. Table per Type
  3. Table per conreate class.

Below goes more detailed description

 

  • Table per Hierarchy (TPH): one table for the entire class inheritance hierarchy. Table includes discriminator column which distinguishes between inheritance classes. This is a default inheritance mapping strategy in Entity Framework.
  • Table per Type (TPT): This approach suggests a separate table for each domain class.
  • Table per Concrete class (TPC): one table for one concrete class, but not for the abstract class. So, if you inherit the abstract class in multiple concrete classes, then the properties of the abstract class will be part of each table of the concrete class.