具有多个数据库架构的EF核心迁移

编程入门 行业动态 更新时间:2024-10-27 17:20:17
本文介绍了具有多个数据库架构的EF核心迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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核心迁移

本文发布于:2023-11-16 07:10:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   架构   核心   数据库   EF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!