title: Entity Framework Code First associations/FK issues and assumptions/defaults
body: <p>I am very confused by the way Entity Framework is able to pick up on relationships between entities. I have a few questions on this.</p>
  
  <p>In a simple test application, I have a table of people, and a table of notes, and a table of picture assets.</p>
  
  <ol>
  <li>There are many pictures, each is owned by a person (a person can own more than one). </li>
  <li>There are many notes, each is owned by a person (a person can own more than one). </li>
  <li>and finally a person has a logo which is a picture.</li>
  </ol>
  
  <p>.</p>
  
  <pre><code>    public class Person
      {
          public int ID { get; set; }
  
          public string name { get; set; }
  
          public Picture logo { get; set; }
      }
  
      public class Note
      {
  
          public int ID { get; set; }
  
          public string Text { get; set; }
  
          public Person Owner { get; set; }
      }
  
  
   public class Picture
      {
  
          public int ID { get; set; }
  
          public string Path { get; set; }
  
          public Person Owner { get; set; }
      }
  </code></pre>
  
  <p>When I try to run, I get the error "Unable to determine the principal end of an association between the types ....".</p>
  
  <p>(If I drop the Person.logo  field, compile/run, then manually add it in to SQL, along with the FK relationship, it works 100% as expected... I just can't seem to work out how to set this from EF itself).</p>
  
  <p>Can you help with the error? I have read quite a few answers here, but, I just can't seem to adapt it to fix my error.</p>
  
  <p>However, now I have a one to many and a many to one (I don't think this is classed as many to many?), I just don't understand how to create people objects, where a FK is non nullable and the FK doesn't exist yet.</p>
  
  <p>A solution I found, which I really don't like is to make the person.picture column nullable, then create a person, followed by creating a picture, then assign a picture to the person object... but, ideally I don't want it nullable. There should always be a picture.</p>