How to use migration programmatically in EntityFramework Codefirst?

c# ef-code-first ef-migrations entity-framework entity-framework-6

Question

I'm working in a project that uses EF Code First. I'm trying to use migration features. I don't want to use Package Console Manager. How can I execute the "Add-Migration" and "Update-Database" programmatically?

add-migration TestMigration01 -force

update-database
1
14
2/2/2016 3:58:32 AM

Accepted Answer

You have a couple of choices. You can use the dbmigrator class from within your code: http://romiller.com/2012/02/09/running-scripting-migrations-from-code/

Or you can use migrate.exe which is handy for running them in a build step, etc. https://msdn.microsoft.com/en-us/data/jj618307.aspx

16
2/2/2016 2:11:23 PM


Related Questions





Related

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