Enable Migrations with Context in Separate Assembly?

前端 未结 4 1766
礼貌的吻别
礼貌的吻别 2020-11-29 18:59

I have one project that I want to run my update-database against but I have my Models and Context in a separate project.

If I run enable-migration

4条回答
  •  一向
    一向 (楼主)
    2020-11-29 19:34

    This will only work in EF 6, but there was a release that added the -ContextProjectName parameter to the -enable-migrations command. By using this command you could do the following:

    enable-migrations -ContextProjectName MyProject.MVC -StartUpProjectName MyProject.MVC 
    -ContextTypeName MyProject.MVC.MyContextFolder.MyContextName -ProjectName MyProject
    

    This will add migrations to your MyProject project using the context in the MyProject.MVC. You need to make sure that the project with the Migrations has a reference to the project with your Context, i.e., MyProject references MyProject.MVC

提交回复
热议问题