Table per type

Table Per Type (TPT) inheritance (also called Vertical inheritance in Telerik Data Access terminology) is represented in the database by separate tables for each class in the hierarchy. Every table contains additional details describing a new type based on another table that is the parent of that table.

In TPT inheritance, each class in the hierarchy is mapped to its own table. A foreign key in the derived table references the primary key of the base table.

In this example, we will use the Database-First approach. Suppose your database contains the following linked tables.

Related database tables for TPT inheritance

Creating the model

  1. Drag all tables from Database Explorer onto the design surface.

Model with TPT inheritance structure

In Entity Framework and LINQ, you need to:

  • Manually remove the available associations.
  • Create correctly defined TPT inheritances.

In NHibernate, TPT inheritances are created automatically unless the Detect Table Per Type Inheritances checkbox is cleared in the model settings.

Model settings for detecting TPT inheritances

Foreign key column configuration

When you create TPT inheritance, you may need to manually define the name of the foreign key column in the derived table if it differs from the primary key column name in the base table. To illustrate this, let us consider the inheritance of the TPTMammal class from the TPTAnimal class.

For example, the TPTMammal class inherits from the TPTAnimal class. The classes are represented by the TPT_Animal and TPT_Mammal tables. These tables are linked by a foreign key:

  • The foreign key column in the TPT_Mammal table references the primary key column in the TPT_Animal table.
  • If both columns have the same name, for example, ID, no additional configuration is required.

Different foreign key names

If the foreign key column in the derived table has a different name than the base table’s primary key, configure it manually:

  1. Open the Inheritance Editor.
  2. In the Column field, enter the foreign key column name.

Inheritance Editor with custom foreign key column

For more information on column parameters, see Database column mapping.

See also

  • Overview
  • Table per hierarchy
  • Table per concrete type
  • Working with inheritances