How to implement IDbContextFactory for use with Entity Framework data migrations

I also hit this problem as i wrote my context to take a connection string name (and then used ninject to provide it).

The process you’ve gone through seems correct, here is a snippet of my class implementation if it’s of any help:

public class MigrationsContextFactory : IDbContextFactory<MyContext>
{
    public MyContext Create()
    {
        return new MyDBContext("connectionStringName");
    }
}

That should be all you need.

Leave a Comment

tech