title: How to control primary key values when seeding data with Entity Framework codefirst
body: <p>I am creating an asp.net mvc4 site using entity framework 5 with codefirst and sql server express 2012.</p>
  
  <p>I have enabled migrations and now do this in my Configuration.Seed method:
  (note that I want to set the primary key to 8 even though this is the first record in the database).</p>
  
  <pre><code>context.ProductCategoryDtoes.AddOrUpdate(x =&gt; x.Id,
      new ProductCategoryDto() { Id = 8, Name = "category1" }
  );
  </code></pre>
  
  <p>My Model object is defined like this:</p>
  
  <pre><code>[Table("ProductCategory")]
  public class ProductCategoryDto {
      public long Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>This results in a table in (SQL SERVER EXPRESS 2012) where the Id column has Identity = true,  Identity seed = 1, identity increment = 1. </p>
  
  <p>Now when I run migrations by doing an <code>PM&gt; Update-Database</code> this result in a row with Id = 1.</p>
  
  <p>So my question are:</p>
  
  <p>1) How can I control the values of auto incremented primary keys when seeding data.</p>
  
  <p>2) If the solution is to increment the key columns seed value, then how is this to be done when I am using <code>Database.SetInitializer(new DropCreateDatabaseAlways&lt;MyContext&gt;());</code>. This will nuke and rebuild the database everytime I update the database, so how would the seed value be updated in the fresh database?</p>