sprocket12
sprocket12

Reputation: 5488

How to apply migrations to EF 7 context on instantiation?

I know I can do :

Database.Migrate();

after the context is ready. But I cannot get EF to do it when initialising my context, like you could do previously with EF 6.1 using Database.SetInitializer and MigrateDatabaseToLatestVersionin the context constructor.

So, how can I ensure that the DB is created or updated and migrated using the available migrations before I make my first call to get data?

Upvotes: 2

Views: 309

Answers (1)

ErikEJ
ErikEJ

Reputation: 41769

Just instantiate the DbContext during app startup, and call Database.Migrate()

Upvotes: 1

Related Questions