Skip to content

abhishekluv/Entity-Framework-Core-Table-per-concrete-Inheritance-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Entity Framework Core Table Per Concrete-Type Inheritance (TPC).

In EF Core 7.0, the table per concrete (also known as TPC) is a mapping strategy where each concrete class in an inheritance hierarchy maps to its table.

The TPC strategy is similar to the TPT strategy except that a different table is created for every concrete type in the hierarchy, but tables are not created for abstract types - hence the name “table-per-concrete-type”.

Things get a bit more complicated for TPC. First, it’s important to understand that EF Core requires that all entities in a hierarchy have a unique key value, even if the entities have different types.

Unlike TPT, there is no common table that can act as the single place where key values live and can be generated. In TPT strategy example for Tables(Vehicles, Cars, Motorcycles), the Cars and Motorcycles tables have Id column as a primary key and foreign key referencing to the Vehicles table. In TPC strategy there is no relationship between differing types like Car or Motorcycle.

This means a simple Identity column (Primary key column) cannot be used.

TPC Strategy will make use of a SQL Server feature called "Sequences".

Key values can be generated by using a single sequence referenced in the default constraint for each table.

About

Entity Framework Core TPC (Table-per-concrete) Inheritance Example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published