问题描述
在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.
在这里您可以找到有关它的更多信息-实体框架代码优先迁移-获取SQL脚本.
Here you could find some more information about it - Entity Framework Code First Migrations - Getting a SQL Script.
这篇关于在Entity Framework 6 C#中获取用于特定迁移的SQL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!