8.4.5.Manually creating EDM Associations (FKs) for the Ingres Tutorial database

The following steps will detail what is required to manually create "Associations" in your Entity Data Model.

Before commencing the process, you will need to determine where these associations exist and their multiplicity (e.g., one-to-one, one-to-many, etc.).

Note: These steps will need to be repeated for each association.

  1. The first Association I will deal with is the relationship between cust_orders and cust_info, identified by the presence of the Scalar Property cust_no in both entities. This is a one-to-one mpmprelationship, as an entry in a customer order may only be associated with one customer's information.



  2. To add the Association, right click on the Customer entity then Add -> Association.

    Figure8.175.add the Association

    add the Association

  3. You will now see the Add Association dialog.

    Figure8.176.Add Association dialog

    Add Association dialog

  4. Once you then hit OK the diagram is refreshed to include the newly created association.

  5. You now need to edit the mappings associated with the newly created association, so right-click the association on the diagram and select

    Table Mapping

    to display the

    Mapping Details


    Figure8.177.Navigation Property name

    Navigation Property name

  6. Click that line reading <Add a Table or View> to reveal a drop down list of all entities.

    Figure8.178.Add a Table or View

    Add a Table or View

  7. Here you need to select the entity on the right/far side of the association (the entity where the foreign key exists). In this example, it is the cust_orders entity.



  8. The Mapping Details pane now refreshes to display both ends of the association, requiring that you provide relevant target store data types in the Column column for the key fields, as depicted here.

    Figure8.180.Mapping Details

    Mapping Details

  9. 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.

    Figure8.181.Build the project

    Build the project

  10. This should result in the following error:



    This error indicates that there are two sources - in this case, the cust_orders entity's Scalar Property cust_no and the Navigation Property cust_info in - which are being mapped to the same target column - the Ingres column cust_orders.cust_no - which is not supported.



  11. The solution is simple! Simply delete the mapping for Scalar Property cust_orders.cust_no since 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 cust_no.

    Right-click on cust_orders.cust_no then Delete.

    Figure8.184.delete the mapping

    delete the mapping

  12. The model diagram will refresh to reflect this change.

    Figure8.185.Model Diagram

    Model Diagram

  13. Build the project, again, using Build -> Build Solution.

    Figure8.186.Build project

    Build project

  14. The project should now be fine.

    Figure8.187.Build Project

    Build Project

You will need to repeat these steps for each association until you have a completed Entity Data Model.

Figure8.188.Entity Data Model

Entity Data Model