In order to avoid it, there is only one approach that is not error prone – to split the ForeignKeyA into two columns, each of them participating in only one foreign key relation. In our example, let’s leave the first column as it is and create a new column called TableBForeignKeyA. Here is the sequence of actions for implementing the change properly:
For reverse mapping:
1. Create a new column in the database table (TableBForeignKeyA) with the same type as ForeignKeyA
2. Reallocate the foreign key between TableA and TableB to point to the new column in TableA (TableBForeignKey instead of ForeignKeyA)
3. Open your Domain Model
4. Update from database TableA and TableB
5. Remove the classes TableA and TableB
6. Add the classes again (to ensure the associations are properly refreshed)
7. Save the Domain Model
For forward mapping:
1. Add new property in the Domain Model TableA class and name it TableBForeignKeyA. The type should be the same as ForeignKeyA’s type.
2. Double-click on the association between TableA and TableB. Change the property for TableA (Source Class section) to TableBForeignKeyA.
3. Save the Domain Model
4. Update the database from the Domain Model
In our sample Domain Model, the diagram will become:
Telerik OpenAccess ORM will keep the proper data integrity between the two foreign key columns and the targets of the relations. However, ensuring the synchronization between the two columns –
ForeignKeyA and
TableBForeignKeyA – will have to be handled manually. Here is an example of how it can be implemented:
For a complete demonstration of the described problem and its solution, you can download the sample C# and VB projects using the links below.