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#?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.