实体框架核心 - 更改“__EFMigrationsHistory”表的模式

时间:2016-07-21 15:06:21

标签: entity-framework-core

是否可以在EntityFramework Core中更改__EFMigrationsHistory表的架构?

2 个答案:

答案 0 :(得分:18)

在致电UseSqlServer时这样做。

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

答案 1 :(得分:7)

查看源代码(HistoryRepository.cs)。您可以在DbContext constructor

中配置自定义迁移表和模式名称
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
    var relationalOptions = RelationalOptionsExtension.Extract(options);
    relationalOptions.MigrationsHistoryTableName = "bar";
    relationalOptions.MigrationsHistoryTableSchema = "foo";
}

OnConfiguring method

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