Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework won't resolve PK-FK relationship with composite primary key?
    primarykey
    data
    text
    <p>I'm trying to set up an EDM on an existing SQL Server infrastructure, and came across a problem.</p> <p>The EDM will <em>not</em> resolve a PK-FK relationship to a composite foreign key.</p> <p>My DB table structure looks something like this (names changed to protect the innocent):</p> <ul> <li>I have a PERSONS table containing an INT column called PerID (PK)</li> <li>I have an OFFICE table containing an INT column called OffID (PK)</li> <li>I am tying these tables together using a table called OFFICEPERSONS, creating a many-to-many relationship between PERSONS and OFFICE. This table has two INT columns, PerID and OffID, which together form a composite primary key.</li> <li>I have a table called OFFICELOCATION that contains two INT columns, LocID and OffID. These two columns comprise a composite primary key. Additionally, OffID is also a FK to the OFFICE table.</li> <li>Finally, I have a table called OFFICEPERSONSLOCATION. This table has three INT columns: PerID, OffID, and LocID. All three columns comprise a composite primary key. LocID and OffID provide a FK relationship to OFFICELOCATION, and OffID and PerID provide a FK relationship to OFFICEPERSONS.</li> </ul> <p>With me so far? Hopefully, I haven't lost you yet. When all is said and done, my structure looks like this: <img src="https://i.stack.imgur.com/qeZlh.png" alt="Database structure diagram"></p> <p>This structure works great in SQL Server. In EDM? Not so much. It will NOT allow me to construct the relation between OFFICEPERSONSLOCATION and OFFICEPERSONS. I get the following error:</p> <blockquote> <p>Error 6037: Foreign key constraint 'FK_OFFICEPERSONSLOCATION_OFFICEPERSONS' has been omitted from the storage model. Column 'OffID' of table 'Model.Store.OFFICEPERSONSLOCATION' is a foreign key participating in multiple relationships. A one-to-one Entity Model will not validate since data inconsistency is possible.</p> </blockquote> <p>Huh? Data inconsistency?!? How?</p> <p>How do I get my entity framework to recognize this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload