Create an EF migration seed script using the Configuration class.

ef-migrations entity-framework


I have EF migrations functioning well, but I also want to use my DbMigrationsConfiguration class to build the sql script for the seed data. When I use Update-Database, the seed data functions OK, however when I use UpdateDatabase -Script, I do not get the sql for the seed inserts. I tried -Verbose on a typical Update-Database, but I still can not see the output of the seed commands.

Can this be done?

5/3/2012 8:23:27 AM

Accepted Answer

It is not feasible, no. The infrastructure that is doing the migration, not the migration itself, is known as the configuration class. For all of your migrations, you have a single configuration class, and itSeed This is performed after each run of the migration; although context may even be used to seed data, this method cannot be a part of the migration since it is done after the migration is finished. Only the migration class's content is programmed.

5/3/2012 8:23:18 AM

Popular Answer

You may also use SSMS to produce the script for you as an alternative/workaround:

1) Create a clean database at the outset using your DB initializer and seed technique. Verify that the information you wish to script is there.

2) In SSMS, right-click the database, choose Tasks > "Generate Scripts...", and then adhere to the wizard's instructions. Make sure to choose "Data only" under "Types of data to script" in the Advanced settings section.

3) Copy the necessary seed statements to your target script from the created script.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow