<docbook><section><title>VirtSybaseAssociations</title><bridgehead class="http://www.w3.org/1999/xhtml:h3">Manually creating EDM Associations (FKs) for the Sybase pubs2 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 the multiplicity (one to one, one to many, etc) before commencing with the following steps.</para><para>NOTE: These steps will need to be repeated for each association.</para><para>1.
 The first Association I will deal with is the relationship between <emphasis>publishers</emphasis> and <emphasis>titles</emphasis> identified by the presence of the scalar property <emphasis>pub_id</emphasis> being present in both entities. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs01.png" /></figure> This is a one to many relationship insomuch that publishers may have zero or many titles.</para><para>2.
 To add the Association, right click on <emphasis>publishers</emphasis> entity.
 Then, click <emphasis>Add</emphasis> -&gt; <emphasis>Association</emphasis>. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs02.png" /></figure></para><para>3.
 You will now see the <emphasis>Add Association</emphasis> dialog. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs03.png" /></figure></para><para>4.
 For this association, the only thing that needs changing is the name of the <emphasis>Navigation Property</emphasis>.
 Change it from <emphasis>publishers</emphasis> to <emphasis>publisher</emphasis> on the <emphasis>publishers</emphasis> end of the association.This more correctly reflects the multiplicity of the association such that a publisher is associated with zero or many titles (plural). <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs04.png" /></figure></para><para>5.
 Hit <emphasis>OK</emphasis>.
 The diagram will be refreshed to include the newly created association. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs05.png" /></figure></para><para>6.
 You now need to edit the mappings associated with the newly created association.
 Highlight the association on the diagram.
 Then, right click it and select <emphasis>Table Mapping</emphasis>.
 This will display the <emphasis>Mapping Details</emphasis> pane. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs06.png" /></figure></para><para>7.
 Click that line that states &lt;Add a Table or View&gt; to reveal a drop down list of all entities. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs07.png" /></figure></para><para>8.
 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>titles</emphasis> entity. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs08.png" /></figure></para><para>9.
 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. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs09.png" /></figure></para><para>10.
 Once the mapping is complete, you can now build the project using <emphasis>Build</emphasis> -&gt; <emphasis>Build Solution</emphasis>.
<figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs10.png" /></figure></para><para>11.
 This should result in the following error which is included here, since I (the author) found it misleading. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs11.png" /></figure> It seems that this error is attempting to say that there are two mappings which map to the same target source column.In this case, it is the target column <emphasis>titles.pub_id</emphasis>.That is, the scalar property <emphasis>pub_id</emphasis> and the Navigation Property <emphasis>publishers</emphasis> in the Invoice entity, both map to the Sybase table column <emphasis>titles.pub_id</emphasis> - which is not supported. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs12.png" /></figure></para><para>12.
 The solution is simple!Delete the scalar property <emphasis>titles.pub_id</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>publishers</emphasis>. Right click on <emphasis>titles.pub_id</emphasis> then <emphasis>Delete</emphasis>. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs13.png" /></figure></para><para>13.
 The model diagram will refresh to reflect this change. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs14.png" /></figure></para><para>14.
 Build the project again, using <emphasis>Build</emphasis> -&gt; <emphasis>Build Solution</emphasis>. <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs15.png" /></figure></para><para>15.
 The project should now build fine.
<figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs16.png" /></figure></para><para>You will need to repeat these steps for each association, until you have a completed Entity Data Model like this - <figure><graphic fileref="VirtSybaseAssociations/SybaseEDMFKs17.png" /></figure> NOTE: It is worthwhile building after each association, since the error messages can be a little confusing.
</para></section></docbook>