<docbook><section><title>VirtOODBCAssociations</title><bridgehead class="http://www.w3.org/1999/xhtml:h3">Manually creating EDM Associations (FKs) for the Microsoft Access Northwind database</bridgehead>
<para>The following steps will detail what is required to manually create <emphasis>Associations</emphasis> in your Entity Data Model.</para>
<para>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.
 <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>Customer</emphasis> and <emphasis>Invoice</emphasis>, identified by the presence of the scalar property <emphasis>Cust_Num</emphasis> in both entities.
 This is a one-to-many relationship, as a Customer may have any number of Invoices.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs01.png" /></figure> </listitem>
<listitem>To add the Association, right click on the <emphasis>Customer</emphasis> entity, then <emphasis>Add</emphasis> -&gt; <emphasis>Association</emphasis>.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs02.png" /></figure> </listitem>
<listitem>You will now see the <emphasis>Add Association</emphasis> dialog.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs04.png" /></figure> </listitem>
<listitem>For this association, the only thing that needs changing is the default name assigned to the <emphasis>Navigation Property</emphasis>.
 Change the default from <emphasis>Invoice</emphasis> to <emphasis>invoices</emphasis> on the <emphasis>Customer</emphasis> end of the association.This better reflects the multiplicity of the association such that a Customer is associated with zero or many Invoices (plural).
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs05.png" /></figure>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.
  </listitem>
<listitem>Hit <emphasis>OK</emphasis>.
 The diagram will be refreshed to include the newly created association.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs06.png" /></figure> </listitem>
<listitem>You now need to edit the mappings associated with the newly created association, so right-click the association on the diagram.
 Then, select <emphasis>Table Mapping</emphasis> to display the <emphasis>Mapping Details</emphasis> pane.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs07.png" /></figure> </listitem>
<listitem>Click the line which reads <emphasis>&lt;Add a Table or View&gt;</emphasis> to reveal a drop down list of all entities.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs08.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>Invoice</emphasis> entity.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs09.png" /></figure> </listitem>
<listitem>The <emphasis>Mapping Details</emphasis> pane now refreshes to display both ends of the association.
 Now, you must provide relevant target store data types in the <emphasis>Column</emphasis> column for the key fields, as depicted here.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs10.png" /></figure> <figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs11.png" /></figure> <figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs12.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 building as each association is made, since the error messages can be a little confusing.</emphasis> <figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs13.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="VirtOODBCAssociations/AccessEDMFKs14.png" /></figure> This error indicates that there are two source columns — in this case, the Invoice entity&#39;s Scalar Property <emphasis>Cust_Num</emphasis> and Navigation Property <emphasis>Customer</emphasis> — which are both mapped to the same target column — the Progress column <emphasis>Invoice.Cust_Num</emphasis> — and this is not supported.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs15.png" /></figure> </listitem>
<listitem>The solution is simple! Simply delete the mapping of the Scalar Property <emphasis>Invoice.Cust_Num</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>Customer</emphasis>. Right click on <emphasis>Invoice.Cust_Num</emphasis> then <emphasis>Delete</emphasis>.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs16.png" /></figure> </listitem>
<listitem>The model diagram will refresh to reflect this change.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs17.png" /></figure> </listitem>
<listitem>Build the project, again, using <emphasis>Build</emphasis> -&gt; <emphasis>Build Solution</emphasis>.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs13.png" /></figure> </listitem>
<listitem>The project should now build fine.
<figure><graphic fileref="VirtOODBCAssociations/AccessEDMFKs18.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="VirtOODBCAssociations/AccessEDMFKs19.png" /></figure> </para>
</section></docbook>