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:
The TPC inheritance for this model can be created in two ways, i.e. manually or automatically.
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:
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.
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:
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:
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:
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.
|
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.
On this page we select the Table-Per-Concrete-Type Hierarchy (TPC) option, specify the new base class name and click Finish.
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:
|