Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script EF migration seed from Configuration class

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 Update-Database, but when I do UpdateDatabase -Script I do not get the sql for the seed inserts. I tried -Verbose on a normal Update-Database but I do not see the seed statements output there either.

Is this possible?

like image 474
Ian1971 Avatar asked May 02 '12 16:05

Ian1971


People also ask

Which method can be used to seed initial data in database using Entity Framework Core?

Seed Data in Entity Framework Core So as soon as we execute our migration files to create and configure the database, we want to populate it with some initial data. This action is called Data Seeding. So, we are using the HasData method to inform EF Core about the data it has to seed.

What is seed script?

A seed script is a script that generates dummy data, possibly using random values or a look up table of acceptable values. The script will create the SQL queries required to insert the data into the database and may also execute the query.


1 Answers

No it is not possible. Configuration class is not part of migration itself - it is infrastructure executing the migration. You have single configuration class for all your migrations and its Seed method is executed after every migration run - you can even use context for seeding data and because of that this method is executed after the migration is completed = it cannot be part of migration. Only content of the migration class is scripted.

like image 97
Ladislav Mrnka Avatar answered Sep 30 '22 07:09

Ladislav Mrnka