C# IdentityDbContext不使用DropCreateDatabaseAlways创建表
我正在从事这个WebApi项目,我正在使用最新版本的身份验证。 我的两个上下文设置如下所示,一个是自动生成用于身份验证的,另一个是我自己的dbcontext用于其他表: ApplicationDbContext用于身份验证表C# IdentityDbContext不使用DropCreateDatabaseAlways创建表,c#,entity-framework,asp.net-web-api2,C#,Entity Framework,Asp.net Web Api2,我正在从事这个WebApi项目,我正在使用最新版本的身份验证。 我的两个上下文设置如下所示,一个是自动生成用于身份验证的,另一个是我自己的dbcontext用于其他表: ApplicationDbContext用于身份验证表 public class IdentityContext : IdentityDbContext<ApplicationUser> { public IdentityContext() : base("DefaultConnection"
public class IdentityContext : IdentityDbContext<ApplicationUser>
{
public IdentityContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static IdentityContext Create()
{
return new IdentityContext();
}
}
DropCreateInitializer
public class DropCreateInitializer : DropCreateDatabaseAlways<Context>
{
protected override void Seed(Context context)
{
// Seeding works nice here
}
}
公共类DropCreateInitializer:DropCreateDatabaseAlways
{
受保护的覆盖无效种子(上下文)
{
//这里播种很好
}
}
我的问题是,当我使用DropCreateDatabaseAlways和seed时,它不会重新创建用于身份验证的表。我就是不明白为什么
请帮忙
您好,Haris您只是在为
上下文
类创建和设置初始值设定项
如果您希望您的IdentityContext
类也总是删除并重新创建,则需要为该类实现一个附加的初始值设定项:
public class IdentityDropCreateInitializer :
DropCreateDatabaseAlways<IdentityContext>
{
protected override void Seed(Context context)
{
//Seed identity tables here
}
}
public class IdentityDropCreateInitializer :
DropCreateDatabaseAlways<IdentityContext>
{
protected override void Seed(Context context)
{
//Seed identity tables here
}
}
public IdentityContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
Database.SetInitializer(new IdentityDropCreateInitializer());
}