使用多个 DB 架构的 EF Core 迁移

EF Core Migrations with Multiple DB Schemas

EF Core 1.1 和 SQL 服务器 2016

我们是 运行 一个微服务应用程序,其中一些微服务具有独立的几个 table。为单个微服务提供许多 table 的解决方案之一是为这些服务提供一个独特的模式(例如,不是 DBO)并将它们全部放在一个数据库中(有利于成本 + 维护)。

这在 EF 6 中工作正常,但是,查看核心中生成的 dbo.__EFMigrationsHistory,看起来核心没有考虑架构。

我知道 EF Core 中的迁移已更改为查看代码而不是数据库,但我的问题是 记录 的版本 dbo.__EFMigrationsHistory table 与模式无关。

您知道我们如何在将迁移写入数据库时​​使 EF Core 架构感知吗?

N.B。 builder.HasDefaultSchema(Constants.SCHEMA); 已在 DBContext 中设置。

builder.HasDefaultSchema() 用于设置模型的模式。 MigrationHistory table 的配置略有不同。您可以阅读更多相关信息 here

来自link,

The simplest scenario is when you just want to change the table name or schema. This can be done using the MigrationsHistoryTable method in OnConfiguring (or ConfigureServices on ASP.NET Core). Here is an example.

protected override void OnConfiguring(DbContextOptionsBuilder options)
    => options.UseSqlServer(
        connectionString,
        x => x.MigrationsHistoryTable("__MyMigrationsHistory", "mySchema"));