Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat 'possible data inconsistency' is entity framework worried about in a 'foreign key participating in multiple relationships' situation?
    primarykey
    data
    text
    <p>Suppose the following database schema:</p> <pre><code>Table A: AId (PK) Table B: BId (PK) Table C: CId (PK) Table AB: AId, BId (composite PK, FKs to A and B), Data Table BC: BId, CId (composite PK, FKs to B and C), Data Table ABC: AId, BId, CId, Data </code></pre> <p>In the database, <code>ABC</code> has two FKs: one to <code>AB</code> on <code>AId</code> and <code>BId</code>, and one to <code>BC</code> on <code>BId</code> and <code>CId</code>.</p> <p>Use the EF Designer and attempt to create a Model from this database.</p> <p>If you have <code>Include foreign key columns in the model</code> <em>checked</em>, it works; but having FK Columns in the model isn't very nice.</p> <p>If you have <code>Include foreign key columns in the model</code> <em>unchecked</em>, only one of the FKs from <code>ABC</code> will be successfully mapped. To see what went wrong, <a href="https://stackoverflow.com/questions/543971/ado-net-entity-framework-update-wizard-will-not-add-tables/546077#546077">you have to view the <code>.edmx</code> xml (thanks Craig!)</a> and you see this error:</p> <blockquote> <p>warning 6037: Foreign key constraint 'FK_ABC_BC' has been omitted from the storage model. Column 'BId' of table 'Model.Store.ABC' 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>I've read <a href="https://stackoverflow.com/questions/582742">the only other mention of this problem I can find on SO</a>, and I don't think this is the same problem. I can't see anything wrong at a <em>database design</em> level. I'm going to work round this for the time being by imposing surrogate keys on <code>AB</code> and <code>BC</code>, but what I'd really like to know is:</p> <p><strong>What possible data inconsistency is EF worried about happening here, if it created a model to match the database?</strong></p> <p>And is there anything I can do to persuade it that everything's going to be OK?</p>
    singulars
    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