Entity Framework Core Interview Question #158

How does EF Core support inheritance mapping?

Advanced Mapping, Interceptors, Value Conversions & Architecture Senior Advanced

Quick Interview Answer

EF Core can map .NET inheritance hierarchies to relational tables using supported inheritance strategies. Common strategies include table-per-hierarchy, table-per-type, and table-per-concrete-type. Each has different query, storage, and performance characteristics, so the mapping should match both the domain and expected workload.

Detailed Explanation

EF Core can map .NET inheritance hierarchies to relational tables using supported inheritance strategies. Common strategies include table-per-hierarchy, table-per-type, and table-per-concrete-type. Each has different query, storage, and performance characteristics, so the mapping should match both the domain and expected workload.

Code Example

public abstract class Payment { public int Id { get; set; } }
public class CardPayment : Payment { public string Last4 { get; set; } = ""; }
public class CashPayment : Payment { }