gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:20:59 30 4
gpt4 key购买 nike

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

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

   "dependencies": {
"EntityFramework": "6.1.3"
,"Moq": "4.2.1502.911"
},

创建初始模型类并使用 AlwaysCreate 数据库初始化程序一切正常。现在需要切换到迁移所以使用 启用迁移 在包管理器控制台中并得到:
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

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

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

最佳答案

编辑 1.0.0: Migrator.EF6现在支持 1.0.0。

RC2 编辑: Migrator.EF6现在支持RC2。

我们需要的是一个封装 EF6 并将命令委托(delegate)给它的 dnx 命令行工具。那是因为 DNX 项目看不到 init.ps1install.ps1获取 Add-Migration 所需的工作(至少现在,见 this )。

实现并不难,但似乎没有人给它时间,所以我最终做了一个。

此解决方案不需要单独的 .csproj , 发生相同的工作流程,但不是 Update-Database你会做dnx ef database update和类似的命令。

说明和样本可以找到here: Migrator.EF6 .

稍后,可能在 RTM 中,您也可以在 DNX 项目中使用这些。这可能就是为什么微软没有制作支持 EF6 迁移的原因。

关于entity-framework-6 - 如何在 asp.net 5 项目中启用迁移(EF6)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30220291/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com