title: EF6 CodeFirst My [Key] Id Column is not auto-incrementing as an identity column should
body: <p>I have several classes that I need to derive from a common base class which holds an Id. Ignoring the all but one of these for the moment, let's say we have:</p>
  
  <pre><code>public class MyBase {
     [Key]
     public int Id { get; set; } 
  }
  public class MyName : MyBase {
     public string Name { get; set; }
  }
  </code></pre>
  
  <p>my context (DataContext) looks like this:</p>
  
  <pre><code>public DbSet&lt;MyName&gt;MyNames { get; set; }
  
  // to avoid having EF make a MyBases table and instead map 
  // MyBase.Id into MyNames and my other derived classes I do this ...
  
  protected override void OnModelCreating((DbModelBuilder modelBuilder) {
     modelBuilder.Entity&lt;MyBase&gt;()
              .Property(c =&gt; c.Id)
              .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
  
     modelBuilder.Entity&lt;MyName&gt;()
              .Map(m =&gt; {
                      m.MapInheritedProperties();
                      m.ToTable("MyNames");
                  });
  }
  </code></pre>
  
  <p>The resulting DB, when I Enable-Migrations, Add-Migration Initial, and Update-Database is that I get no table called MyBases, but instead I get the Id column in MyNames </p>
  
  <pre><code>   dbo.MyNames
     -----------
     Id (PK, int, not null)
     Name (nvarchar(max), null)
  </code></pre>
  
  <p>So far so good, all of that compiles and builds, and then I test it using something like the following:</p>
  
  <pre><code>   using ( DataContext dc = new DataContext()) {
        var jj = new MyName { Name = "Janice Joplin" };
        dc.MyNames.Add(jj);
        dc.SaveChanges();
  
        var jh = new MyName { Name = "Jimmy Hendrix" };
        dc.MyNames.Add(jh);
        dc.SaveChanges();
     }
  </code></pre>
  
  <p>This works the first time (Janice is added with Id = 0) but <em>not</em> the second ... Jimmy gets a DUPLICATE KEY exception. Note (for full disclosure) I'm actually creating the jj and jh objects in another part of my code, then passing them into this method (above) as MyBase objects, then casting them back to MyName objects if that's what they are. I hope that isn't a problem.</p>
  
  <p>I guess if everything were in one table, the Id could be marked as Identity and @@IDENTITY could be used to assign the object Id value.  Perhaps I will need to make a MyBases table after all, and create that record first, then duplicate the Id into the derived tables in a transaction. What's the best approach for this?    </p>
  
  <p>Any help for this EF6 CodeFirst newbie would be appreciated.  THANKS. </p>