[英]Entity Framework 6 code-first migrations generation
I want to be able to selectively run SQL commands genereted by Entity Framework 6 migration, so I could alter or filter them. 我希望能够有选择地运行由Entity Framework 6迁移产生的SQL命令,因此可以更改或过滤它们。 So ideally I would have some code like this :
因此,理想情况下,我将有如下代码:
var migration = EF.GetMigrationOperations();
var filteredOperations = migration.Where(...);
SqlContext.ExecuteCommands(filteredOperations);
This is just a pseudocode describing my desire. 这只是描述我的愿望的伪代码。 So is there any way to do this ?
那么有什么办法可以做到这一点? I have not found one yet.
我还没有找到。 Usecase for this is for automated db migrations eg filter DROP statements until new version of app is uploaded.
用例是用于自动数据库迁移,例如过滤DROP语句,直到上载新版本的应用程序为止。
I finally resolved it partially. 我终于部分解决了。 To get at least .sql script in code I used https://romiller.com/2012/02/09/running-scripting-migrations-from-code/ with basic context factory.
为了在代码中至少获取.sql脚本,我使用了带有基本上下文工厂的https://romiller.com/2012/02/09/running-scripting-migrations-from-code/ 。 Another way to get sole operations in code as initially requested would be to use brutal reflection on
HistoryRepository
class of EntityFramework. 最初要求在代码中获得唯一操作的另一种方法是对EntityFramework的
HistoryRepository
类使用残酷的反射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.