Get SQL file for specific migration in Entity Framework 6 C#

白昼怎懂夜的黑 提交于 2019-12-18 12:29:51

问题


In Entity Framework 6, I need to get the SQL script for specific migration file and I already update the database. I found that in update-database command I can add script parameter to export it 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?

i also i tried the below, and i got empty SQL file Update database command


回答1:


Yes, you could do like followed:

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

To create a script for all migrations execute following:

Update-Database -Script -SourceMigration: $InitialDatabase

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

Here you could find some more information about it - Entity Framework Code First Migrations - Getting a SQL 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.




回答2:


If you want to generate -Script for migration N, you specify -SourceMigration N-1 (previous migration) and -TargetMigration N




回答3:


If you're now in .net core use

Script-Migration -From <PreviousMigration> -To <LastMigration>


来源:https://stackoverflow.com/questions/49552550/get-sql-file-for-specific-migration-in-entity-framework-6-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!