How to implement IDbContextFactory for use with Entity Framework data migrations

前端 未结 1 884
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 03:50

I am trying to use Entity Framework data migrations, as described in this post.

However, when I try to execute the Enable-Migrations step, I receive the

相关标签:
1条回答
  • 2020-12-05 04:38

    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.

    0 讨论(0)
提交回复
热议问题