Table Per Concrete Type

The Table Per Concrete (TPC) Type inheritance is an inheritance that is used when the database contains two or more tables with sets of identical columns.

For example, suppose that in the database we have the TPC_Horse and TPC_Dog tables. Both these tables contain the following identical columns: BirthDate and Genus.

Within the Database First approach, used for the purpose of this example, first, we move the TPC_Horse and TPC_Dog tables from the Database Explorer window onto the design surface to create classes with the same respective names:

Images_TPC_Start

The TPC inheritance for this model can be created in two ways, i.e. manually or automatically.

 

ExpandedToggleIcon        Manual creation of the inheritance

After the classes are added to the diagram, we move identical properties (ID, BirthDate and Genus) from one of the classes onto the diagram surface.

This displays the following dialog box:

Images_Choose-Action-TPC-EF

In the dialog box above, we select New base class and enter a name for the abstract class, for example, TPCBaseEntity, and click OK.

The Inheritance Editor dialog box is displayed.

Images_Inheritance-Editor-TPC-EF

In this dialog we select Table Per Concrete Type in the Type combo-box and click OK.

After this, we right-click the TPCBaseEntity class and select Mapping Details in the context menu. In the Default tab of the Entity Mapping Details dialog box we delete all mapping for the class by selecting <Delete> in the Storage Entities list.

Then we call the Class Editor dialog box for the TPCBaseEntity class and set its Inheritance Modifier to Abstract.

Now we set Column Mappings for the TPCDog class in the Default tab of the Entity Mapping Details dialog box:

Images_TPC-Entity-Mapping-Details-EF

At this stage, a TPC inheritance is created between the TPCDog class, from which we moved the identical properties and the TPCBaseEntity class. The model looks as follows:

Images_TCP_Model_2

Now we shall move the identical properties from the TPCHorse class onto the diagram surface. The Model Refactoring dialog box is displayed again with the following selection:

Images_Choose-Action-TPC2-EF

If the automatic selection of the parameters is different, it will be necessary to select the Existing base class option, then select the TPCBaseEntity class from the corresponding drop-down list and click OK.

 

ExpandedToggleIcon        Automatic creation of the inheritance

After the required classes are added to the diagram area, we select them, call their context menu, and select the Model Refactoring menu item.

The Choose Action page of the Model Refactoring Wizard is displayed.

images_refactoring-wizard-TPC

On this page we select the Table-Per-Concrete-Type Hierarchy (TPC) option, specify the new base class name and click Finish.

note Note

Click the Preview link to preview the new base class properties in the Class Editor dialog box.

Thus, we get the classes connected with TPC inheritance.

The result we get is the same irrespective of the approach to inheritance creation we use, but automatic inheritance creation takes fewer steps and all mapping customization is done by Entity Developer automatically. For more information on automatic inheritance creation and other model refactoring options, see Model Refactoring Wizard.

Finally, we get the following model:

Images_TPC_Model_Final

 

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.