如何在 asp.net 5 项目中启用迁移(EF6)? [英] How to enable migrations (EF6) in an asp.net 5 project?

查看:21
本文介绍了如何在 asp.net 5 项目中启用迁移(EF6)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I created a new class library (package) project (prior to VS 2015 RC used the even worse name of asp.net class library to represent the data layer. Just to be clear this is the newer kproj style structure.

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

Added EF 6.1.3 to project.json. Currently only targeting DNX451.

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

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

Created initial model classes and using a AlwaysCreate database initializer everything works fine. Now need to switch to migrations so used Enable-Migrations in the package manager console and got:

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,对吗?

For EF7 migrations the package manager is not supported for migration commands. Instead there is a new ef command run through dnu but that new process is just for EF7 not EF6 right?

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

Why does package manager think Enable-Migrations is invalid even though EF6 has been referenced?

推荐答案

EDIT for 1.0.0: Migrator.EF6 现在支持 1.0.0.

EDIT for 1.0.0: Migrator.EF6 now supports 1.0.0.

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

EDIT for RC2: Migrator.EF6 now supports RC2.

我们需要的是一个 dnx 命令行工具,它封装了 EF6 并将命令委托给它.这是因为 DNX 项目不会看到使 Add-Migration 工作所需的 init.ps1install.ps1(至少对于现在,请参阅 this).

What we need is a dnx command line tool that wraps EF6 and delegates commands to it. That's because DNX projects won't see init.ps1 and install.ps1 that are needed to get Add-Migration to work (at least for now, see this).

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

The implementation isn't that hard but no one seems to have given it time so I ended up doing one.

此解决方案不需要单独的 .csproj,会发生相同的工作流程,但您将使用 dnx ef 数据库更新而不是 Update-Database/code> 和类似的命令.

This solution doesn't require a separate .csproj, the same workflow happens but instead of Update-Database you'll do dnx ef database update and similar commands.

可以在这里找到说明和示例:Migrator.EF6.

稍后,可能在 RTM 中,您也可以在 DNX 项目中使用这些.这可能就是为什么 Microsoft 还没有开发支持 EF6 迁移的原因.

Later on, probably in RTM, you'll be able to use these in DNX projects as well. And that's probably why Microsoft hasn't made one to support EF6 migrations.

这篇关于如何在 asp.net 5 项目中启用迁移(EF6)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆