EntityFramework.Core 2.0预览 - OnConfiguring方法未调用

时间:2017-06-19 18:34:34

标签: c# entity-framework

我正在测试EF core 2.0预览。但是,当我尝试使用DbContext获取EF core 1.1.2的新实例时,OnConfiguring方法不会被调用:

public class DatabaseContext : DbContext
{
    DatabasesType database_type;
    string URI;

    public DbSet<User> user;

    public DatabaseContext(DatabasesType database_type, string URI) : base()
    {
        this.database_type = database_type;
        this.URI = URI;            
    }


    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        switch (database_type)
        {
            case DatabasesType.MySQL:
                optionsBuilder.UseMySql(URI); break;
            case DatabasesType.SQLite:
                optionsBuilder.UseSqlite(URI); break;
        }
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // ...
    }
}

发生了什么事?有类似错误的人?

谢谢!

0 个答案:

没有答案