How to: Create One-to-One Associations with Vertical Inheritance
This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.
There are two ways to represent one-to-one associations in the Visual Designer: using one-to-one relations or creating vertical inheritance. This topic is focused on the second approach.
Database First Mapping
Suppose, you have the following tables in the database:
There is a foreign key, defined in CustomerDetails.ID column, pointing to the CustomerMain.ID column.
You have a domain model representing both tables.
In order to model one-to-one association, you need to perform the following steps:
- Delete the association.
-
Add an inheritance between the classes, making sure that the class corresponding to the table that holds the foreign key is the child class. In this case, the CustomerDetails table contains the foreign key, that's why it should be the child class and the CustomerMain entity should be the base class. Select the objects to be included in the inheritance by clicking the derived entity first on the design surface and then clicking the base entity on the design surface.
-
Set the Inheritance Strategy of the child class (CustomerDetail) to Vertical.
-
Set the Discriminator Value for the base class (CustomerMain) to {no}.
-
Delete the identity property (Id) of the child class (CustomerDetail) – it will implicitly use the identity of the parent class (CustomerMain).
-
Select the child class (CustomerDetail) and ensure that it is mapped to the corresponding table (in this example, to the CustomerDetails table). Open the Mapping Details Editor, navigate to the Table Mappings section and ensure that the child class (CustomerDetail) is mapped to the corresponding table (in this example, to the CustomerDetails table). If not, select the table from the Mapped to drop-down.
Save the Domain Model.
Model First Mapping
To see how to implement this scenario, check out the How to: Model Vertical Inheritance with the Visual Designer topic.