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

前端 未结 4 640
滥情空心
滥情空心 2020-12-28 20:32

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 ca

相关标签:
4条回答
  • 2020-12-28 20:38

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

    0 讨论(0)
  • 2020-12-28 20:56

    You can run the following command from Package manager console. It will generate a temporary file and will open it in VS:

    Script-Migration
    
    0 讨论(0)
  • 2020-12-28 20:59

    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
    

    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.

    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.

    0 讨论(0)
  • 2020-12-28 21:02

    If you're now in .net core use

    Script-Migration -From <PreviousMigration> -To <LastMigration>
    
    0 讨论(0)
提交回复
热议问题