I can run the following from the package manager console
update-database -targetmigration:0 -force
How can I do the same thing via C#?
I can run the following from the package manager console
update-database -targetmigration:0 -force
How can I do the same thing via C#?
There is a Database Initializer you can use to achieve the migration to latest version on startup (or better, the dbinitializer will kick in on first db access), the MigrateDatabaseToLatestVersion, you use it like that:
Database.SetInitializer<ObjectContext>(
new MigrateDatabaseToLatestVersion<ObjectContext, Configuration>());
Source: https://stackoverflow.com/a/10850935/1551
You can also just set automigrations to true, and I'm sure you can configure force to happen also if necesary, though it probably will not by default.