是否可以从两个上下文创建单个类?

时间:2016-11-16 10:02:10

标签: asp.net-mvc entity-framework asp.net-identity

我很想知道是否可以将这两个下面的类合并为一个单独的类。

第一个DbContext:

static void submit() {
    Dimension screen = mobileDriver.manage().window().getSize();
    mobileDriver.tap(1, screen.getWidth() - 20, screen.getHeight() - 20);
}

第二个DbContext:

public class ApplicationDbContext : IdentityDbContext<BusinessAccount>
{
    public ApplicationDbContext()
        : base("MySQLConnectionString", throwIfV1Schema: false)
    {
    }

    public DbSet<Sector> Sectors { get; set; }

    public DbSet<Campus> Campuss { get; set; }
    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}

1 个答案:

答案 0 :(得分:0)

从DbContext继承IdentityDbContext

public class IdentityDbContext<T1>: DbContext
{
   // Implementation goes here
}

ApplicationDbContext

继承IdentityDbContext<BusinessAccount>
public class ApplicationDbContext : IdentityDbContext<BusinessAccount>
{
    public ApplicationDbContext()
        : base("MySQLConnectionString", throwIfV1Schema: false)
    {
    }

    public DbSet<Sector> Sectors { get; set; }    
    public DbSet<Campus> Campuss { get; set; }
    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}