Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, when issues like this you should take a look at your migration files generated (or if you don't have them just enable it) - it shows in a 'higher level' form of tables/mappings generated for you. </p> <p><strong>Problem is that you have 'one to one' relationship and your <code>ProjectDocAccess</code> to <code>ProjectDoc</code> is mapped with pk -> pk</strong>. Code first automatically does that for you in these cases as that's the only supported way of making the <code>one to one</code>. </p> <p>So your <code>ProjectDocAccessID</code> is at all times mapped == <code>the same</code> as your <code>ProjectDocID</code>. </p> <p>The <code>ProjectDocID</code> is auto-generated - but you need to put the access-id to match it yourself. (I'm guessing that could be automated but strictly in db terms it's not).</p> <blockquote> <p>So, it can't auto-generate things. It has to be copied from the <code>principal</code> table, where the 'optional' is. </p> </blockquote> <p>With your current entities it is what it is - but you could rearrange things maybe (though one-to-one are tough to make and could lead to issues if you don't get it right). </p> <p>There is an option to create <code>one to one</code> using FK-s only (which would then allow you to place an 'independent' primary key on your 'access' table) - but requires manually injecting SQL <code>CONSTRAINT</code> - e.g. see this page - <a href="http://weblogs.asp.net/manavi/archive/2011/05/01/associations-in-ef-4-1-code-first-part-5-one-to-one-foreign-key-associations.aspx" rel="nofollow">http://weblogs.asp.net/manavi/archive/2011/05/01/associations-in-ef-4-1-code-first-part-5-one-to-one-foreign-key-associations.aspx</a></p>
 

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