title: EF Code First: Add row to table with a non-identity primary key
body: <p>To reduce this problem to a simple version, I've created this table:</p>
  
  <pre><code>create table TestTable(id int primary key, descr varchar(50))
  </code></pre>
  
  <p>Note that the <code>id</code> field is not an identity field.  Now, if I try to use EF Code First to insert a row:</p>
  
  <pre><code>[Table("TestTable")]
  public class TestTable
  {
      [Key]
      public int id { get; set; }
      public string descr { get; set; }
  }
  
  public class TestContext : DbContext
  {
      public TestContext(string connectionString) : base(connectionString) {}
      public DbSet&lt;TestTable&gt; TestTables { get; set; }
  }
  
  static void Main()
  {
      const string connectionString = "...";
      using (var db = new TestContext(connectionString))
      {
          db.TestTables.Add(new TestTable { id = 42, descr = "hallo" });
          db.SaveChanges();
      }
  }
  </code></pre>
  
  <p>The result is an exception:</p>
  
  <blockquote>
    <p>Cannot insert the value NULL into column 'id', table 'TestTable';
    column does not allow nulls.</p>
  </blockquote>
  
  <p>But the code that inserts the row specifies <code>id = 42</code>.  Any clue or hint welcome.</p>