我正在尝试使用Entity Framework,Autofac和Identity 2.0设置具有管理员角色的初始用户 这是我的应用程序上下文类:
public class ApplicationContext<TUser> : IdentityDbContext<TUser> where TUser : IdentityUser
{
public ApplicationContext(string conectionString) : base(conectionString)
{
Database.SetInitializer(new MyContextInitializer());
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//entities builder and configuration
}
}
我的自定义初始化程序:
class MyContextInitializer : DropCreateDatabaseIfModelChanges<ApplicationContext<IdentityUser>>
{
protected override void Seed(ApplicationContext<IdentityUser> context)
{
//seeding data
}
}
问题是从不调用种子方法。怎么回事以及如何解决这个问题?谢谢你提前!