title: Entity Framework - Migrations - Code First - Seeding per Migration
body: <p>I am looking into Migrations in an effort to clean up our deployment processes.  The less manual intervention required when pushing a change to production the better.</p>
  
  <p>I have run into 3 major snags with the migrations system.  They are show stoppers if I can not figure out a clean way around them.</p>
  
  <p><strong>1. How do I add Seed data per migration:</strong></p>
  
  <p>I execute the command "add-migration" which scaffolds a new migration file with Up and Down functions.  Now, I want to automatically make changes to the data with both Up and Down changes.  I don't want to add the Seed data to the Configuration.Seed method as this runs for all migrations which ends in all sorts of duplication problems.</p>
  
  <p><strong>2. If the above is not possible, how do I avoid duplications?</strong></p>
  
  <p>I have an enum that I loop through to add the values to the database.</p>
  
  <pre><code>foreach(var enumValue in Enum.GetValues(typeof(Access.Level)))
  {
      context.Access.AddOrUpdate(
          new Access { AccessId = ((int)enumValue), Name = enumValue.ToString() }
      );
  }
  context.SaveChanges();
  </code></pre>
  
  <p>Even though I am using AddOrUpdate, I still get duplicates in the database.  The above code brings me to my 3rd and final problem:</p>
  
  <p><strong>3. How can I seed Primary Keys?</strong></p>
  
  <p>My enumerable with the above code is:</p>
  
  <pre><code>public class Access
  {
      public enum Level
      {
          None = 10,
          Read = 20,
          ReadWrite = 30
      }
      public int AccessId { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>I am specifying the values that I want as my primary key, but Entity Framework seems to ignore it.  They still end up being 1,2,3.  How do I get it to be 10,20,30?</p>
  
  <p>Are these limitations of EF at the moment or are they intentional constraints to prevent some other kind of catastrophe I am not seeing?</p>