如何在asp.net 5项目中启用迁移(EF6)? [英] How to enable migrations (EF6) in an asp.net 5 project?
问题描述
我创建了一个新的类库(包)项目(在VS 2015 RC之前,使用更糟糕的asp.net类库名来表示数据层,只要清楚这是更新的kproj样式结构。 p>
将EF 6.1.3添加到project.json目前仅针对DNX451。
依赖:{
EntityFramework:6.1.3
,Moq:4.2.1502.911
},
创建初始模型类,并使用AlwaysCreate数据库初始化器,一切正常,现在需要切换到所使用的迁移启用迁移在包管理器控制台中得到:
启用迁移:术语启用迁移不被识别为名称的cmdlet,函数,脚本文件或可操作的程序。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试
在行:1 char:1
+启用迁移
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
对于EF7迁移,迁移命令不支持软件包管理器。相反,有一个新的ef命令通过dnu运行,但新流程只是为EF7而不是EF6对吗?
为什么程序包管理器认为启用迁移无效,即使EF6已被引用?
编辑1.0.0: Migrator.EF6 现在支持1.0.0。
RC2编辑: Migrator.EF6 现在支持RC2。
我们需要的是一个dnx命令行工具,用于包装EF6并将命令委托给它。这是因为DNX项目不会看到 init.ps1
和 install.ps1
c>添加迁移工作(至少现在看这个)。
实现不是那么难,但没有人似乎给了它的时间,所以我最终做了一个。
此解决方案不需要单独的 .csproj
,相同的工作流程发生,而不是更新数据库
你会做 dnx ef数据库更新
和类似的命令。
说明和样本可以发现 here:Migrator.EF6 。
之后,大概在RTM中,您也可以在DNX项目中使用这些。这也许是为什么微软还没有支持EF6迁移。
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.
Added EF 6.1.3 to project.json. Currently only targeting DNX451.
"dependencies": {
"EntityFramework": "6.1.3"
,"Moq": "4.2.1502.911"
},
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
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?
Why does package manager think Enable-Migrations is invalid even though EF6 has been referenced?
EDIT for 1.0.0: Migrator.EF6 now supports 1.0.0.
EDIT for RC2: Migrator.EF6 now supports RC2.
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.
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.
Instructions and samples can be found here: Migrator.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屋!