对于一个DbContext可以自动迁移,而不是在同一个项目中进行自动迁移? [英] Is it possible to have automatic migrations for one DbContext and not for another in the same project?

查看:145
本文介绍了对于一个DbContext可以自动迁移,而不是在同一个项目中进行自动迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一个项目中有两个DbContexts,但自动迁移只能启用一个。是可能吗?

I would like to have two DbContexts in the same project but automatic migrations enabled only for one. Is it possible?

推荐答案

是的。每个 DbMigrationsConfiguration 通过 ContextKey 绑定到一个特定的 DbContext 。一旦你有超过 DbContext 启用迁移命令需要 ContextTypeName 参数。可以轻松地为一个DbContext运行 Enable-Migrations ,并将其忽略。

It is. Each DbMigrationsConfiguration is bound to one specific DbContext via ContextKey. As soon as you have more than on DbContext, the Enable-Migrations command requires the -ContextTypeName parameter. One can easily just run Enable-Migrations for one DbContext and omit it for the other.

这篇关于对于一个DbContext可以自动迁移,而不是在同一个项目中进行自动迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆