title: Strange thing when seeding users and roles in ASP.NET Identity 2.0.1
body: <p>I found this piece does not work properly:</p>
  
  <pre><code>protected override void Seed(PintxoLista.Models.ApplicationDbContext context)
  {
      var store = new RoleStore&lt;IdentityRole&gt;(context);
      var manager = new RoleManager&lt;IdentityRole&gt;(store);
      if (!context.Roles.Any(r =&gt; r.Name == "WeddingGuest"))
      {
          var role = new IdentityRole { Name = "WeedingGuest" };
          manager.Create(role);
      }
  
      if (!context.Roles.Any(r =&gt; r.Name == "BrideGroom"))
      {
          var role = new IdentityRole { Name = "BrideGroom" };
          manager.Create(role);
      }
  
      if (System.Diagnostics.Debugger.IsAttached == false)
      {
          System.Diagnostics.Debugger.Launch();
      }
  
      context.Users.AddOrUpdate(i =&gt; i.Id,
          new ApplicationUser
      {
          Id = "1",
          UserName = "han",
          Email = "hansolo1@rebels.com",
          PasswordHash = new PasswordHasher().HashPassword("1"),
          SecurityStamp = string.Empty
      },
      new ApplicationUser
      {
          Id = "2",
          UserName = "lando",
          Email = "lando@rebels.com",
          PasswordHash = new PasswordHasher().HashPassword("1"),
          SecurityStamp = string.Empty
      });
  
      var userManager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(context));
      userManager.AddToRole("1", "WeedingGuest");
      userManager.AddToRole("2", "BrideGroom");
  }
  </code></pre>
  
  <p>The roles are created but the users are not and then the first <code>AddToRole</code> fails. Instead, if the users are add (or updated) to the database first then it works fine.</p>
  
  <pre><code>protected override void Seed(PintxoLista.Models.ApplicationDbContext context)
  {
      context.Users.AddOrUpdate(i =&gt; i.Id,
          new ApplicationUser
      {
          Id = "1",
          UserName = "han",
          Email = "hansolo1@rebels.com",
          PasswordHash = new PasswordHasher().HashPassword("1"),
          SecurityStamp = string.Empty
      }, new ApplicationUser
      {
          Id = "2",
          UserName = "lando",
          Email = "lando@rebels.com",
          PasswordHash = new PasswordHasher().HashPassword("1"),
          SecurityStamp = string.Empty
      });
  
      var store = new RoleStore&lt;IdentityRole&gt;(context);
      var manager = new RoleManager&lt;IdentityRole&gt;(store);
      if (!context.Roles.Any(r =&gt; r.Name == "WeddingGuest"))
      {
          var role = new IdentityRole { Name = "WeedingGuest" };
          manager.Create(role);
      }
  
      if (!context.Roles.Any(r =&gt; r.Name == "BrideGroom"))
      {
          var role = new IdentityRole { Name = "BrideGroom" };
          manager.Create(role);
      }
  
      var userManager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(context));
      userManager.AddToRole("1", "WeedingGuest");
      userManager.AddToRole("2", "BrideGroom");
  }
  </code></pre>
  
  <p>Can anyone explain this apparently strange behaviour? Why the users must be created first? Thank you!!</p>