title: EF6 Data Seeding Issue with System.Data.Entity.Migrations.AddOrUpdate
body: <p>EF 6.2,
  SQL Server 2016 Developer Edition,
  .Net 4.5.2</p>
  
  <p>I'm running into some issues with the <a href="https://msdn.microsoft.com/en-us/library/hh846514(v=vs.103).aspx" rel="nofollow noreferrer">AddOrUpdate</a> extension method. 
  As I understand the method, one should define, with a lambda expression, the unique field that should be used to determine if a record is to be updated or added. But mine seems to be ignoring this and trying to add every time. This example is using the Identity class AspNetRole but the same issue is happening for all entities in the context.  </p>
  
  <pre><code>public class UserSeeder
  {    
      public static void Seed(MyIdentityDbContext context)
      {
  
  
          HashSet&lt;AspNetRole&gt; roles = new HashSet&lt;AspNetRole&gt;();
  
          AspNetRole systemAdmin = new AspNetRole() { Id = "269E684F-9542-4F6A-8029-7516AA2ECD61", Name = "System Admin" };
          AspNetRole admin = new AspNetRole() { Id = "BE70FDF9-FCD5-4894-AE71-DA324A7D751E", Name = "Administrator" };
          AspNetRole normalUser = new AspNetRole() { Id = "D9C66DC0-190F-463A-88B0-8E1E4ED96BAF", Name = "User" };
  
          roles.Add(systemAdmin);
          roles.Add(admin);
          roles.Add(normalUser);
  
          foreach (AspNetRole role in roles)
          {
              context.Roles.AddOrUpdate(r =&gt;r.Id, role);
              //context.Roles.AddOrUpdate(role);
              //both throw same error
          }
          context.SaveChanges();
      }
  }
  </code></pre>
  
  <p>And in the Configuration.cs file generated by Enabling Migrations.</p>
  
  <pre><code>//  This method will be called after migrating to the latest version.
  protected override void Seed(MyIdentityDbContext context)
  {
      UserSeeder.Seed(context);
      base.Seed(context);
  }
  </code></pre>
  
  <p>This is the error I'm getting for both the call using the lambda and just passing in the object. I have a suspicion there is some configuration I'm not setting correctly cause this was working last week and when I check git, no changes have been made to any of the DAL project's files. </p>
  
  <blockquote>
    <p>Violation of PRIMARY KEY constraint 'PK_dbo.AspNetRoles'. Cannot insert duplicate key in object 'dbo.AspNetRoles'. The duplicate key value is (269E684F-9542-4F6A-8029-7516AA2ECD61).</p>
  </blockquote>
  
  <p>Additionally, the db is up-to-date and the application doesn't throw any data access errors in runtime so the connection is fine and the model is in sync. We just can't get the seed method to work the way the examples show.</p>