Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IdentityDbContext不使用DropCreateDatabaseAlways创建表_C#_Entity Framework_Asp.net Web Api2 - Fatal编程技术网

C# IdentityDbContext不使用DropCreateDatabaseAlways创建表

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"

我正在从事这个WebApi项目,我正在使用最新版本的身份验证。 我的两个上下文设置如下所示,一个是自动生成用于身份验证的,另一个是我自己的dbcontext用于其他表:

ApplicationDbContext用于身份验证表

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());
    }