Table per Type

A Table Per Type (TPT) inheritance (or Vertical inheritance in Telerik Data Access terminology) is an inheritance that is represented in the database by several separate tables. Every such table contains additional details describing a new type based on another table that is the parent of that table.

In this example, we shall use the Database-First approach.

Suppose that there are the following linked tables in the database:

Images_TPT_DB

The next step is to move all these tables from the Database Explorer window onto the design surface. When this step is completed, the model is as follows:

Images_TPT_Model_TDA

Note that in Entity Framework and in LINQ we need to remove manually the available associations and create correctly defined TPT inheritances, while in NHibernate this is done automatically, unless the Detect Table Per Type Inheritances check box is cleared in the model settings (see below).

Images_DetectTPTsettingTDA

Note also that it may be necessary to manually define the name of the foreign key column of the database table that corresponds to the derived class in the inheritance if this name differs from the name of the database primary key column of the database table that corresponds to the base class of the inheritance.

To illustrate this point, let us consider the inheritance of the TPTMammal class from the TPTAnimal class.

These classes are represented in the database with the TPT_Animal and TPT_Mammal tables. The association between these tables is created between the foreign key column of the latter table and the primary key column of the former table. The names of the column are identical (ID).

If the foreign key column of the TPT_Mammal table has a different name, then, for the TPT inheritance in the model, it must be manually entered under Column in the Inheritance Editor window:

Images_INheritanceEditorRed

For more information on the parameters of columns and how to define them, see the Database Column Mapping topic.

 

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.