5

In previous versions of Entity Framework code-first migrations could be controlled programmatically with the DbMigrator class (e.g. check for and apply available migrations). Does that class still exist somewhere or is there a functional replacement? I found a post on an early RC version that indicated a substitute but that too seems to be missing from Core 1.0. I can control my migrations through CLI without issue but I think an in-code solution for custom tooling scenarios is going to be needed.

1
  • For those coming to this question looking for something similar, but for ASP.NET MVC Core 1.0 and Entity Framework Core 1.0, see this: stackoverflow.com/questions/38282138/… Commented Dec 10, 2016 at 15:12

1 Answer 1

7

The functional replacement can be found in a few places, primarily in the API found in the Microsoft.EntityFrameworkCore.Migrations namespace.

Some places to look:

With the exception of IMigrator.Migrate, using these API usually means pulling the service out of internal EF Core's service container. This is done by calling .GetService<TService>() on your dbcontext.

Example:

var migrator = context.GetService<IMigrator>().Migrate();
Sign up to request clarification or add additional context in comments.

2 Comments

The GetService<T> method is not available to my context. I'm assuming it's an extension method? What dependent package and namespace contains that method?
It's in the Microsoft.EntityFrameworkCore.Infrastructure namespace. You don't need an extra package.

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.