简体   繁体   中英

Entity-Framework what is the difference between Migrations Seed and ContextInitializer Seed?

I am learning EF in school and I'm currently working with EF 5, MVC 5, I can't get my head around the Migrations and ContextInitializer. I am following this guide because I find it more suited for my project. I did read and almost build the updated guide but, because I'm using a slightly older EF5, I couldn't get it working.
My question is: In the newer, EF6 guide, there is this Migrations.cs which has a Seed method, in the older EF5 guide, the Seed method is in the [Model]ContextInitializer, what is the best practice of the two? I did understand that the Migration is a little better in terms of updating the DataBase with the Enable-Migrations Add-Migration MyTitle and Update-Database commands in Package Manager Console.
If this is a silly question, I beg you pardon me.

Migration Seed method is for seeding data right after database migration and DB Initializer Seed method is for seeding data right after Database initialization.

You can use Db Initialize Seed method to add initial data to DB right after Initialization , but you can use Migration Seed method to check and/or add new data or do special things right after Migration .

It can be a little bit confusing but if you think about it, you will understand it well. These are different cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM