Script EF migration seed from Configuration class

前端 未结 3 1486
终归单人心
终归单人心 2021-01-01 11:07

I have EF migrations working nicely, but I also want to generate the sql script for the seed data from my DbMigrationsConfiguration class. The seed data runs ok when I do Up

3条回答
  •  不知归路
    2021-01-01 11:25

    Another solution/workaround is to have SSMS generate the script for you:

    1) Start with a clean database generated by your DB initializer and seed method. Make sure the data you want scripted is in there.

    2) Using SSMS, right-click the database, go to Tasks > "Generate Scripts...", and follow the wizard. Under Advanced options, be sure to select "Data only" for "Types of data to script".

    3) From the generated script, copy required seed statements over to your target script.

提交回复
热议问题