是否可以从已经声明了DbContextOptions类型的另一个DbContext派生一个DbContext?

时间:2018-09-11 17:17:49

标签: .net entity-framework core

我已经定义了一个DbContext,并绑定了一个DbContextOptions类型。

public SimpleContentDbContext(DbContextOptions<SimpleContentDbContext> options) : base(options){}

是否可以从SimpleContentDbContext派生DbContext?这是我的尝试。尝试创建DbContextOptions <>时出现转换错误。

public class FOTMDbContext : SimpleContentDbContext, IFOTMDbContext
{

    private static DbContextOptions<FOTMDbContext> _options;
    private static DbContextOptions<SimpleContentDbContext> _options1;

    protected FOTMDbContext() { }

    public FOTMDbContext( DbContextOptions<FOTMDbContext> options)
           : base(ModifyOptions(options ))
    {
        _options = options;
    }

    private static DbContextOptions<SimpleContentDbContext> ModifyOptions(DbContextOptions<FOTMDbContext> opt)
    {
        var optionsBuilder = new DbContextOptionsBuilder(opt);
        return _options1 = (DbContextOptions<SimpleContentDbContext>)optionsBuilder.Options;
    }

    public DbSet<Practioner> Practioners { get; set; }
}

错误表明,基本上无法将对象从DbContextOptions [FOTMDbContext]投射到DbContextOptions [SimpleContentDbContext] ...

0 个答案:

没有答案