1

I can run the following from the package manager console

update-database -targetmigration:0 -force

How can I do the same thing via C#?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
WhiskerBiscuit
  • 4,795
  • 8
  • 62
  • 100

1 Answers1

1

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.

Community
  • 1
  • 1
Chris Ballance
  • 33,810
  • 26
  • 104
  • 151