The Table per Class Hierarchy (TPH) inheritance is modeled by having a single database table for all the entity classes in the inheritance hierarchy. The TPH inheritance is useful in cases where all the information about the related entities is stored in a single table. For example, using the earlier scenario, let's try to model the database in such a way that it will only contain a single table called Workers
to store the Employee
and Vendor
details. Let's try to visualize this table:
Now what will happen in this case is that the common fields will be populated whenever we create a type of worker. Salary
will only contain a value if the worker is of type Employee
. The HourlyRate
field will be null
in this case. If the worker is of type Vendor
, then the HourlyRate
field will have a value, and Salary
will be null
.