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

asp.net-core entity-framework-6

Question

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?

1
11
5/13/2015 4:18:56 PM

Popular Answer

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.

4
6/28/2016 5:06:18 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow