EF Core 1.1和SQL Server 2016
EF Core 1.1 and SQL Server 2016
我们正在运行一个微服务应用程序,其中一些微服务具有独立的少数表。为单个微服务提供许多表的解决方案之一是为这些服务提供唯一的架构(例如,不是DBO),并将所有服务都放在一个数据库中(有利于成本+维护)。
We are running a microservice application with some microservices having independent few tables. One of the solutions to have many tables for individual microservice, is to give these services a unique schema (e.g. not DBO) and put all of them in one database (good for cost + maintenance).
在EF 6中效果很好,但是查看生成的dbo。__EFMigrationsHistory在核心中,看来核心没有考虑架构。
That works fine in EF 6, however, looking at the generated dbo.__EFMigrationsHistory in core, it looks like core doesn't take the schema into account.
我知道EF Core中的迁移已更改为查看代码而不是数据库,但是我的问题是dbo中记录的版本。__EFMigrationsHistory表与模式无关
I am aware that the migration in EF Core has changed to look in the code rather than the DB, but my problem is the version that is recorded in the dbo.__EFMigrationsHistory table is schema-agnostic.
您知道在将EF Core模式写入数据库迁移时如何使EF Core模式感知吗?
Do you know how can we make EF Core schema-aware when it writes the migration to the db?
NB builder.HasDefaultSchema(Constants.SCHEMA); 已在DBContext中设置。
N.B. builder.HasDefaultSchema(Constants.SCHEMA); is already set in the DBContext.
推荐答案builder.HasDefaultSchema()用于设置模型的架构。 MigrationHistory表的配置略有不同。您可以在此处
builder.HasDefaultSchema() is used to set schema for model. MigrationHistory table is configured bit differently. You can read more about it here
从链接中,
最简单的情况是当您只想更改表名时或架构。可以使用OnConfiguring(或ASP.NET Core上的ConfigureServices)中的MigrationsHistoryTable方法来完成。这是一个示例。
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"));
更多推荐
具有多个数据库架构的EF核心迁移
发布评论