<docbook><section><title>VirtIngresAssociations</title><para> </para>
<bridgehead class="http://www.w3.org/1999/xhtml:h3">Manually creating EDM Associations (FKs) for the Ingres Tutorial database</bridgehead>
<para>The following steps will detail what is required to manually create <emphasis>Associations</emphasis> in your Entity Data Model.</para>
<para>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.).
 <emphasis><emphasis>NOTE:</emphasis> These steps will need to be repeated for each association.</emphasis></para>
<orderedlist spacing="compact"><listitem>The first Association I will deal with is the relationship between <emphasis>cust_orders</emphasis> and <emphasis>cust_info</emphasis>, identified by the presence of the Scalar Property <emphasis>cust_no</emphasis> in both entities.
 This is a one-to-one relationship, as an entry in a customer order may only be associated with one customer&#39;s information.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc02.png" /></figure> </listitem>
<listitem>To add the Association, right-click on the <emphasis>Customer</emphasis> entity.
 Then, click <emphasis>Add</emphasis> -&gt; <emphasis>Association</emphasis>.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc03.png" /></figure> </listitem>
<listitem>You will now see the <emphasis>Add Association</emphasis> dialog.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc04.png" /></figure> </listitem>
<listitem>Hit <emphasis>OK</emphasis>.
 The diagram will be refreshed to include the newly created association. </listitem>
<listitem>You now need to edit the mappings associated with the newly created association, so right-click the association on the diagram and select <emphasis>Table Mapping</emphasis> to display the <emphasis>Mapping Details</emphasis> pane.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc05.png" /></figure> </listitem>
<listitem>Click the line that reads <emphasis>&lt;Add a Table or View&gt;</emphasis> to reveal a drop down list of all entities.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc06.png" /></figure> </listitem>
<listitem>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 <emphasis>cust_orders</emphasis> entity.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc07.png" /></figure> </listitem>
<listitem>The <emphasis>Mapping Details</emphasis> pane now refreshes to display both ends of the association.
 You will now be required to provide relevant target store data types in the <emphasis>Column</emphasis> column for the key fields, as depicted here.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc08.png" /></figure> </listitem>
<listitem>Once the mapping is complete, you can build the project using <emphasis>Build</emphasis> -&gt; <emphasis>Build Solution</emphasis>.
 <emphasis><emphasis>NOTE:</emphasis> It is worthwhile to (re)build as each association is made, since the error messages can be a little confusing.</emphasis> <figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc09.png" /></figure> </listitem>
<listitem>This should result in the following error, which is included here, since I (the author) found it misleading.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc10.png" /></figure> This error indicates that there are two sources — in this case, the <emphasis>cust_orders</emphasis> entity&#39;s Scalar Property <emphasis>cust_no</emphasis> and the Navigation Property <emphasis>cust_info</emphasis> in  — which are being mapped to the same target column — the Ingres column <emphasis>cust_orders.cust_no</emphasis> — which is not supported.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc11.png" /></figure> </listitem>
<listitem>The solution is simple!  Delete the mapping for Scalar Property <emphasis>cust_orders.cust_no</emphasis>.
 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 <emphasis>cust_no</emphasis>. Right-click on <emphasis>cust_orders.cust_no</emphasis>.
 Then, click <emphasis>Delete</emphasis>.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc12.png" /></figure> </listitem>
<listitem>The model diagram will refresh to reflect this change.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc14.png" /></figure> </listitem>
<listitem>Build the project, again, using <emphasis>Build</emphasis> -&gt; <emphasis>Build Solution</emphasis>.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc09.png" /></figure> </listitem>
<listitem>The project should now build fine.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc13.png" /></figure></listitem>
</orderedlist><para>You will need to repeat these steps for each association until you have a completed Entity Data Model.
<figure><graphic fileref="VirtIngresAssociations/VirtIngresAssc01.png" /></figure> </para>
</section></docbook>