Table per class hierarchy requires nullable columns for derived classes

When persisting class hierarchies, all properties in derived classes must be nullable.

Problem

A common pattern for representing class hierarchies in relational databases is to use a table that will have columns for each of the base and derived classes. For example, imagine we have a Vehicle base class and two derived classes, LandVehicle and AirVehicle:

Problem

Vehicles class model

Using the Table per class hierarchy (also called single table inheritance), this could be represented as follows:

Table per class hierarchy mapping table

You may have noticed that the columns that correspond to ...

Get Entity Framework Core Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.