Entity Framework Core - change schema of “__EFMigrationsHistory” table

∥☆過路亽.° 提交于 2019-12-10 02:39:55

问题


Is it possible to change schema of __EFMigrationsHistory table in EntityFramework Core?


回答1:


Do it in your call to UseSqlServer.

optionsBuilder
    .UseSqlServer(
        "...",
        x => x.MigrationsHistoryTable(
            HistoryRepository.DefaultTableName,
            "mySchema"));



回答2:


Looking into source code (HistoryRepository.cs). You can configure custom migrations table and schema names, inside DbContext constructor

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
    var relationalOptions = RelationalOptionsExtension.Extract(options);
    relationalOptions.MigrationsHistoryTableName = "bar";
    relationalOptions.MigrationsHistoryTableSchema = "foo";
}

or inside OnConfiguring method

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    var relationalOptions = RelationalOptionsExtension.Extract(optionsBuilder.Options);
    relationalOptions.MigrationsHistoryTableName = "bar";
    relationalOptions.MigrationsHistoryTableSchema = "foo";
}


来源:https://stackoverflow.com/questions/38507861/entity-framework-core-change-schema-of-efmigrationshistory-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!