title: EF: Cannot insert value NULL into column 'ID'
body: <p>Trying to insert a row into my database using Entity Framework. I assign all of the values upon insert except ID, which is the primary key, and I'd like it to get auto-incremented by the SQL Server DB.</p>
  
  <p>My table definition/class:</p>
  
  <pre><code>public partial class T_SurfacePick
  {
      [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int ID { get; set; }
  
      public int? BoreholeID { get; set; }
      public int? AuthoredNameID { get; set; }
      public int? LoadFormat { get; set; }
      public double? PickDepth { get; set; }
      public int? OwningAuthorID { get; set; }
      public int? QualityID { get; set; }
      public double? CustomData { get; set; }
  }
  </code></pre>
  
  <p>When I call the <code>SaveChanges()</code> method, I get an error </p>
  
  <blockquote>
    <p>Cannot insert the value NULL into column 'ID'</p>
  </blockquote>
  
  <p>How do I get this column to auto-increment itself? I'd like not to have to worry about keeping track of the <code>ID</code> and assigning it myself.</p>
  
  <p>I'm trying to use the code-first approach. Here's an example of part of my decision tree for inserts/updates:</p>
  
  <pre><code>if (MenefeePick == null) // New top
  {
     var Pick = new T_SurfacePick { BoreholeID = Wellbore.ID, AuthoredNameID = MenefeeAN.ID, LoadFormat = 1, PickDepth = Menefee, OwningAuthorID = ProgAuthor.ID, QualityID = -1, CustomData = null };
     db.T_SurfacePick.Add(Pick);
  }
  else // Update top
  {
      MenefeePick.PickDepth = Menefee;
  }
  db.SaveChanges();
  </code></pre>
  
  <p>I'll further qualify by mentioning that my model uses an existing database from a software product.</p>