如何在asp.net 5项目中启用迁移(EF6)?

Ger*_*vis 11 entity-framework-6 asp.net-core

我创建了一个新的类库(包)项目(在VS 2015 RC之前使用了更糟糕的asp.net类库名称来表示数据层.只是要清楚这是更新的kproj样式结构.

将EF 6.1.3添加到project.json.目前仅针对DNX451.

   "dependencies": {
        "EntityFramework": "6.1.3"
        ,"Moq": "4.2.1502.911"
    },
Run Code Online (Sandbox Code Playgroud)

创建初始模型类并使用AlwaysCreate数据库初始化程序一切正常.现在需要切换到迁移,以便在包管理器控制台中使用Enable-Migrations并获得:

Enable-Migrations : The term 'Enable-Migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Enable-Migrations
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Enable-Migrations:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

对于EF7迁移,迁移命令不支持包管理器.相反,有一个新的ef命令在dnu中运行,但是新进程只适用于EF7而不是EF6吗?

为什么包管理器认为即使引用了EF6,Enable-Migrations仍然无效?

tug*_*erk 3

为什么尽管引用了 EF6,包管理器仍认为 Enable-Migrations 无效?

因为我假设并且非常确定 ASP.NET 5 项目不会调用包内的安装和卸载 PowerShell 脚本,而 EF 6 包必须将迁移命令添加到包管理器控制台。您最好的运气是尝试将命令行工具(我相信它称为 migrate.exe,不确定)集成到 EF6 NuGet 包中。

  • 一般而言,命令和 VS2015 RC 也存在问题:https://github.com/aspnet/EntityFramework/issues/1950。如果您将 EF6 工作拆分为单独的程序集并使用旧的 csproj 样式,您应该能够在 DNX451 应用程序中引用它并让命令起作用(假设您使用链接中的解决方法) (2认同)