1

I have inherited an ASP.NET application, using Entity Framework 6, and have enabled migrations. In my Global.asax, I have this:

using (var context = new MyContext()) { Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext, MyConfiguration>()); context.Database.Initialize(true); } 

The problem is that every time my application needs to start up (due to IIS shutting it down for example), this logic is run, even though in most cases there is no migration to be performed. This significantly slows down the processing of the requests.

What are my options here? What is best practice? I could disable this and use the Package Manager Console to perform migrations manually, but that kind of beats the purpose (though if there are no other options, I'm prepared to do this).

2
  • 1
    Automatic migrations have been removed in EF Core (here is some reasoning), so looks like the direction is to perform migrations manually. Commented Mar 22, 2017 at 9:29
  • @IvanStoev If you add your comment as an answer, I'll mark it as the correct answer. Commented Apr 13, 2017 at 10:51

1 Answer 1

2

The EF6 automatic migrations seem to introduce several issues (not only performance), so the EF Core team decided to remove them from EF Core (you can read some reasoning here).

Since EF Core is the EF6 successor (the future of the Entity Framework), looks like the recommendation (best practice) is to disable it and perform migrations manually.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.