在Entity Framework 6 C#中获取用于特定迁移的SQL文件 [英] Get SQL file for specific migration in Entity Framework 6 C#

查看:66
本文介绍了在Entity Framework 6 C#中获取用于特定迁移的SQL文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Entity Framework 6中,我需要获取特定迁移文件的SQL脚本,并且已经更新了数据库.我发现在update-database命令中可以添加脚本参数以将迁移导出到SQL,但是我已经更新了数据库.我在Entity Framework Core中找到了一个名为Script-Migration的命令,脚本名称作为参数.实体框架中是否有任何类似的命令?

In Entity Framework 6, I need to get the SQL script for specific migration file and I already updated the database. I found that in update-database command I can add script parameter to export the migration to SQL, but I already updated the database. I found in Entity Framework Core, a command called Script-Migration with script name as an argument. Is there any similar command in Entity framework?

我也尝试了建议"更新数据库命令",但是我得到了空的SQL文件.

I also tried the suggestion "Update database command", but I got an empty SQL file.

推荐答案

是的,您可以按以下方式生成迁移SQL:

Yes, you could generate the migration-SQL as follows:

Update-Database -Script -SourceMigration: <pointFromWichYouWantToStartWithGeneration> -TargetMigration: <pointWhereToEndWithGeneration>

要为所有迁移创建脚本,请执行以下操作:

To create a script for all migrations execute the following:

Update-Database -Script -SourceMigration: $InitialDatabase

不是将更改应用到数据库,而是将生成一个SQL脚本文件.因此,即使已将迁移应用到数据库,您也可以生成SQL脚本.

Instead of applying the changes to database it will generate a SQL script file. Therefore you could generate a SQL Script even if the migration was already applied to the database.

在这里您可以找到有关它的更多信息-

Here you could find some more information about it - Entity Framework Code First Migrations - Getting a SQL Script.

运行Update-Database命令,但是这次指定–Script标志,以便将更改写入脚本而不是应用.我们还将指定源迁移和目标迁移来为其生成脚本.

Run the Update-Database command but this time specify the –Script flag so that changes are written to a script rather than applied. We’ll also specify a source and target migration to generate the script for.

这篇关于在Entity Framework 6 C#中获取用于特定迁移的SQL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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