%VOSWARNING%
%META:TOPICPARENT{name="VirtProgressEntityFrameworkUsage"}%
---+++Manually creating EDM Associations (FKs) for the Progress isports database
The following steps will detail what is required to manually create *Associations* in your Entity Data Model.
You will need to determine where these associations exist and their multiplicity (one-to-one, one-to-many, etc.) before commencing with the following steps. NOTE: These steps will need to be repeated for each association.
1 The first Association I will deal with is the relationship between Customer
and Invoice
, identified by the presence of the scalar property Cust_Num
in both entities. This is a one-to-many relationship, as a Customer may have any number of Invoices.
%BR%%BR%%BR%%BR%
1 To add the Association, right click on the Customer
entity, then *Add* -> *Association*.
%BR%%BR%%BR%%BR%
1 You will now see the *Add Association* dialog.
%BR%%BR%%BR%%BR%
1 For this association, the only thing that needs changing is the default name assigned to the *Navigation Property*. Change the default from Invoice
to invoices
on the Customer
end of the association.%BR%%BR%This better reflects the multiplicity of the association such that a Customer is associated with zero or many Invoices (plural).
%BR%%BR%%BR%%BR%Typically, here is where you will - 1) Select the entity at each end of the association, 2) Select the multiplicity of each end of the association, and 3) Provide suitable names for the association and its navigation properties. %BR%%BR%
1 Hit *OK*. The diagram will be refreshed to include the newly created association.
%BR%%BR%%BR%%BR%
1 You now need to edit the mappings associated with the newly created association, so right-click the association on the diagram. Then, select *Table Mapping* to display the *Mapping Details* pane.
%BR%%BR%%BR%%BR%
1 Click the line which reads <Add a Table or View> to reveal a drop down list of all entities.
%BR%%BR%%BR%%BR%
1 Here you need to select the entity on the right/far side of the association (the entity where the foreign key exists).%BR%%BR%In this example, it is the Invoice
entity.
%BR%%BR%%BR%%BR%
1 The *Mapping Details* pane now refreshes to display both ends of the association. Now, you must provide relevant target store data types in the *Column* column for the key fields, as depicted here.
%BR%%BR%
%BR%%BR%
%BR%%BR%%BR%%BR%
1 Once the mapping is complete, you can build the project using *Build* -> *Build Solution*. NOTE: It is worthwhile building as each association is made, since the error messages can be a little confusing.
%BR%%BR%%BR%%BR%
1 This should result in the following error, which is included here since I (the author) found it misleading.
%BR%%BR%%BR%%BR%
This error indicates that there are two source columns — in this case, the Invoice entity's Scalar Property Cust_Num
and Navigation Property Customer
— which are both mapped to the same target column — the Progress column Invoice.Cust_Num
— and this is not supported.
%BR%%BR%%BR%%BR%
1 The solution is simple! Simply delete the mapping of the Scalar Property Invoice.Cust_Num
. Its only purpose is to hold data representing a relationship/association (it is a Foreign Key), which has already been represented by the newly created association and resulting Navigation Property Customer
.%BR%%BR%
Right click on Invoice.Cust_Num
then *Delete*.
%BR%%BR%%BR%%BR%
1 The model diagram will refresh to reflect this change.
%BR%%BR%%BR%%BR%
1 Build the project, again, using *Build* -> *Build Solution*.
%BR%%BR%%BR%%BR%
1 The project should now build fine.
%BR%%BR%%BR%%BR%
You will need to repeat these steps for each association, until you have a completed Entity Data Model.
%BR%%BR%%BR%%BR%