How to enable migrations (EF6) in an asp.net 5 project?

孤街醉人 提交于 2019-11-29 09:32:57

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.

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

Because I assume and am quite sure that ASP.NET 5 projects don't invoke install and uninstall PowerShell scripts inside the packages which EF 6 package has to add the migration commands to package manager console. Your best luck is to try to integrate the command line tool (I believe it is called migrate.exe, not sure) inside the EF6 NuGet package.

I have managed to get round this by creating an old .csproj project which the Enable-Migrations command works. The only difference is that instead of having a separate copy of the files, i have added them all by reference, using the "Add By Link" option when adding an existing file.

Now i can add migrations etc and change the files as needed, and these changes will automatically reflect in my .xproj as it is the same files.

Luca Morelli

In asp.net 5 project you have to use entity framework 7 and use the ef migration command from command line.

I just done a recap here How can I manage EF 6 migrations in visual studio 2015?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!