How to: Control the Reference Property Name
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.
This article will show you how to control the names of generated reference navigation properties in the child class in a 1:m association.
The name of the reference navigation property can be based on:
- The name of the parent class in the association
- The name of the foreign key property of the child class in the association
Based on the name of the parent class in the association
By default reference navigation property names are based on the name of the parent class in the association. For the example, consider the schema of the Package-Location database:
- Create a new Telerik Data Access Class Library project.
- Choose the Populate from database option and click the Next button.
- Select the Package-Location database at the Setup Database Connection screen and click the Next button.
- At the Choose Database Items screen select both the Location and Package tables and click the Next button.
-
At the Define Naming Rules screen choose the Navigations tab. Notice that the Base Reference Name On setting is set to Class.
-
Click the Finish button to complete the wizard. The resulting Domain Model should look like this:
Notice the two reference navigation property of the Package class - Location has its name based on the name of the parent class Location.
Based on the name of the foreign key property of the child class in the association
Now consider a scenario where the database schema has a second relationship:
In such scenario, if the names of the generated reference navigation properties are based on the name of the parent class, they will become ambiguous - Location and Location1:
To prevent that you can instead use the name of the foreign key property of the child class by following the next steps.
- Create a new Telerik Data Access Class Library project.
- Choose the Populate from database option and click the Next button.
- Select the Package-Location database at the Setup Database Connection screen and click the Next button.
- At the Choose Database Items screen select both the Location and Package tables and click the Next button.
-
At the Define Naming Rules screen choose the Navigations tab. Set the Base Reference Name On setting to Foreign Key Property. To achieve higher clarity of the resulting names, use Remove Suffix(es) from Foreign Key to remove the Id suffix.
-
Click the Finish button to complete the wizard. The resulting Domain Model should look like this:
We recommend you uncheck the Apply Property Naming Rules on the Reference Side checkbox when you are basing the names of the reference properties on the foreign key property.
The two reference navigation properties of the Package class are now named SourceLocation and DestinationLocation - based on the respective foreign key properties for the association - SourceLocationId and DestinationLocationId respectively.
As you may have noticed in the current case, the names of the collection navigation properties in the parent class Location have become ambiguous - Packages and Packages1. To see how to modify them, please refer to How to: Control the Collection Property Name