Inheritance Mapping in EF Core: TPH vs TPT vs TPC in SQL Server
Your e-commerce system has different types of products: physical products, digital downloads, and subscriptions. Each type has common properties (name, price) and specific properties (shipping weight for physical, download URL for digital, billing frequency for subscriptions).
How you map this inheritance hierarchy to SQL Server tables dramatically affects query performance, storage efficiency, and maintainability.
The Three Inheritance Strategies
EF Core provides three approaches to map inheritance hierarchies to relational databases:
Table-per-Hierarchy (TPH)
All types stored in a single table with a discriminator column
Table-per-Type (TPT)
Shared properties in base table, specific properties in derived tables
Table-per-Concrete-Class (TPC)
Each concrete type gets its own table with all properties
Let’s examine each approach with a practical example.
Domain Model Setup
public abstract class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public string Description { get; set; }
public DateTime CreatedAt { get; set; }
public bool IsActive { get; set; }
}
public class PhysicalProduct : Product
{
public double Weight { get; set; }
public string Dimensions { get; set; }
public decimal ShippingCost { get; set; }
public int StockQuantity { get; set; }
}
public class DigitalProduct : Product
{
public string DownloadUrl { get; set; }
public long FileSizeBytes { get; set …