Entity Framework Core 1.0.1 add-migration

人盡茶涼 提交于 2019-12-11 02:26:11

问题


Since EF Core migrated to Microsoft.EntityFrameworkCore.* (instead of EntityFramework.*), it seems that the recommended command line to add db migrations is back to add-migration from package manager.

ef core add migration documentation

However it seems there isn't a package anymore for commands and that the package installation of v 1.0.1 doesn't add any command.

The error message I'm getting when running Add-Migration is

Cannot execute this command because EntityFramework.Commands is not installed in the startup project 'project name'.

Did I miss something? Is there a new way to add the commands or so? Thanks for your help!


回答1:


In order to use the Package Manager Console commands (e.g. Add-Migration) on .NET Core projects, your project.json will need to look something like this.

{
    "dependencies": {
        "Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
        "Microsoft.EntityFrameworkCore.Tools": {
            "version": "1.0.0-preview2-final",
            "type": "build"
        }
    },
    "tools": {
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
    }
}

The Microsoft.EntityFrameworkCore.Tools under dependencies ensures the PowerShell commands get registered. It's "type": "build" ensures they don't get published with your application. The Microsoft.EntityFrameworkCore.Tools under dependencies ensures the dotnet ef command gets registered (which is called by the PowerShell commands).



来源:https://stackoverflow.com/questions/39751199/entity-framework-core-1-0-1-add-migration

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