Saatgut-Einheiten UND Benutzer, Rollen?
Wie Sie Samen von Benutzern, Rollen und app-spezifischen Entitäten? Es scheint, als ob die IdentityModel Ziele Ihren eigenen Kontext?
internal sealed class Configuration : DbMigrationsConfiguration<Project.Models.SchoolContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(Project.Models.SchoolContext context)
{
//Seed the Entities
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" }
// );
//
}
}
vs.
protected override void Seed(Project.Models.ApplicationDbContext context)
{
if (!context.Roles.Any(r => r.Name == "AppAdmin"))
{
var store = new RoleStore<IdentityRole>(context);
var manager = new RoleManager<IdentityRole>(store);
var role = new IdentityRole { Name = "AppAdmin" };
manager.Create(role);
}
if (!context.Users.Any(u => u.UserName == "founder"))
{
var store = new UserStore<ApplicationUser>(context);
var manager = new UserManager<ApplicationUser>(store);
var user = new ApplicationUser {UserName = "founder"};
manager.Create(user, "ChangeItAsap!");
manager.AddToRole(user.Id, "AppAdmin");
}
}
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ich nicht Saatgut aus der migration, sondern verwenden Sie das Kontext-db Initialisierung. Mein Rahmen stammt aus IdentityDbContext also ich benutze diese Methode, um Saatgut von Benutzern und Rollen:
Aufruf und Initialisierung von ctor:
Dann meine Nachkommen code: