title: EF Code First giving me error Cannot insert explicit value for identity column in table 'People' when IDENTITY_INSERT is set to OFF.
body: <p>I'm trying out Entity Framework 4's Code First (EF CodeFirst 0.8) and am running into a problem with a simple model that has a 1 &lt;--> 0..1 relationship, between <code>Person</code> and <code>Profile</code>. Here's how they're defined:</p>
  
  <pre><code>public class Person
  {
      public int PersonId { get; set; }
  
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public DateTime? DOB { get; set; }
  
      public virtual Profile Profile { get; set; }
  }
  
  public class Profile
  {
      public int ProfileId { get; set; }
      public int PersonId { get; set; }
      public string DisplayName { get; set; }
  
      public virtual Person Person { get; set; }
  }
  </code></pre>
  
  <p>The DB context looks like this:</p>
  
  <pre><code>public class BodyDB : DbContext
  {
      public DbSet&lt;Person&gt; People { get; set; }   
  }
  </code></pre>
  
  <p>I didn't define a <code>DbSet</code> for <code>Profile</code> because I consider <code>People</code> to be its aggregate root. When I try to add a new <code>Person</code> - even one without a <code>Profile</code> with this code:</p>
  
  <pre><code>public Person Add(Person newPerson)
  {
      Person person = _bodyBookEntities.People.Add(newPerson);
      _bodyBookEntities.SaveChanges();
      return person;
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Cannot insert explicit value for identity column in table 'People' when IDENTITY_INSERT is set to OFF. </p>
  </blockquote>
  
  <p>The <code>newPerson</code> object has a <code>0</code> for the <code>PersonId</code> property when I call <code>People.Add()</code>. The database tables are <code>People</code> and <code>Profiles</code>. <code>PersonId</code> is the PK of <code>People</code> and is an auto-increment Identity. <code>ProfileId</code> is the PK of <code>Profiles</code> and is an auto-incement Identity. <code>PersonId</code> is a non-null int column of <code>Profiles</code>.</p>
  
  <p>What am I doing wrong? I think I'm adhering to all the EF Code First's convention over configuration rules.</p>