EF迁移脚本以退出条件的迁移
我想在条件的基础上以代码第一次方法中的迁移。
假设,如果条件为真,我想在不更改数据库的情况下退出迁移。
I want to abort the migration in code first approach on a condition basis.
Suppose, if the condition is true, I want to exit the migration without making changes to the database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
migrationBuilder.sql(String,boolean)方法,因此创建一个SQL脚本,并使用您想使用
(如果... else
条件)进行操作。然后创建一个空迁移,然后在sql()
方法中写下脚本,为 verbatim 字符串。如果您不知道如何为迁移创建脚本,请使用脚本移民。
我认为您无法运行查询或对迁移的注入服务,因为实体 - 框架命令行工具分析了您的代码,但不运行startup.cs类。
This should be possible with MigrationBuilder.Sql(String, Boolean) method, so create an SQL script with what you want to do with
IF...ELSE
conditions. Then create an empty migration and write the script in theSql()
method as a verbatim string.If you don't know how to create a script for your migration, use Script-Migration.
I don't think you can run queries or inject services to migrations, since the Entity-framework command-line tool analyzes your code but does not run the startup.cs class.