简体   繁体   English

实体框架6代码优先的迁移生成

[英]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.

相关问题 如何正确地促进实体框架代码优先迁移到生产中? - how to properly promote Entity Framework code-first migrations into production? 无法创建实体框架代码优先迁移 - Can't create Entity Framework code-first migrations 在实体框架代码优先迁移中选择列名 - Choosing name of column in entity framework code-first migrations 使用代码优先迁移的Entity Framework从SQL Server到Oracle - From SQL Server to Oracle using Entity Framework with code-first Migrations 序列在实体框架代码优先迁移中包含多个元素错误 - Sequence contains more than one element error in Entity framework code-first migrations 实体框架代码优先迁移不生成外键并忽略 ForeignKey 数据注释 - Entity Framework code-first migrations does not generate a foreign key and ignores the ForeignKey data annotation Entity Framework Core 代码优先在生成迁移时执行其他操作 - Entity Framework Core code-first perform additional actions when generating migrations Entity Framework Core 2.1,使用代码优先迁移重命名表而不删除和创建新表 - Entity Framework Core 2.1, rename table using code-first migrations without dropping and creating new table 如何使用迁移将描述添加到 Entity Framework Core 代码优先中的列? - How to add description to columns in Entity Framework Core code-first using migrations? 实体框架代码第一次迁移 - Entity Framework Code First Migrations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM