title: Entity Framework Code First - Cannot insert duplicate key in object 'db'
body: <p>I'm using the new EF code first to one project of mine, and i'm getting a weird error, my mode is:</p>
  
  <pre><code>abstract class Member
  {
     public virtual int MemberId;
    ... some other stuff
  
  }
  
  class User : Member
  {
      public virtual string Name;
      ... some more props no new key defined
  }
  
  class MyDbContext
  {
      public DbSet&lt;User&gt; Users {get;set;}
  }
  </code></pre>
  
  <p>The result of the deployment to SQL Server is just ok, i've a Members Table and a Users Table (TPC).
  Now in my main i've the following code:</p>
  
  <pre><code>static Main()
  {
     User x,y;
     using(MyDbContext ctx = new MyDbContext())
     {
  
  
      x = ctx.Users.Create();
      y = ctx.Users.Create();
      x.Name = "SomeUser";
      y.Name = "SomeUser2";
      ctx.SaveChanges();
  
     }
  }
  </code></pre>
  
  <p>On save changes i get:</p>
  
  <blockquote>
    <p>"Unhandled Exception:
    System.Data.Entity.Infrastructure.DbUpdateException:
    An error occurred while updating the
    entries. See the inner exception for
    de tails. --->
    System.Data.UpdateException: An error
    occurred while updating the entries.
    See the inner exception for details.
    ---> System.Data.SqlClient .SqlException: Violation of PRIMARY
    KEY constraint
    'PK_<em>Users</em>_0CF04B1821B6055D'. Cannot
    insert duplicate key in object
    'dbo.Users'."</p>
  </blockquote>
  
  <p>The MemberId by default is identity so i just not seeing what's going on here. i've tried to create the instances with new and Attach them to the context but the error was the same, any ideas? 
  The database is empty!</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: Forgot to told that Member is an abstract class sorry bout that.</p>