asp.net 5(vnext)和实体框架6

时间:2015-06-02 13:37:27

标签: entity-framework asp.net-core

我正在努力将一个Entity Framework数据上下文添加到ASP.NET 5类库中,并且我一直收到System.Data.Entity未被引用的错误。

只有在构建目标设置为.net 4.5.1时,才能添加对它的引用。这不适用于.net core 5

我使用的是VS 2015 RC,安装的ASP.NET 5的DNVM版本为1.0.0-beta4

任何想法,如果这已被移动或为什么它不起作用?

修改:添加了project.json文件

{
    "version": "1.0.0-*",
    "description": "",
    "authors": [ "" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
        "EntityFramework": "6.1.3",
        "Microsoft.DataAnnotations": "1.0.0-beta1"
    },

    "frameworks": {
        "dnx451": { }
        "dnxcore50": {
            "dependencies": {
                "System.Collections": "4.0.10-beta-22816",
                "System.Linq": "4.0.0-beta-22816",
                "System.Threading": "4.0.10-beta-22816",
                "Microsoft.CSharp": "4.0.0-beta-22816"
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

EntityFramework 6ASP.Net core 5不兼容,这就是您遇到此错误的原因 如果您要使用EF6,则必须取消定位dnxcore50

修改:将示例添加到目标'dnxcore50
你的project.json将是:

{
    "version": "1.0.0-*",
    "description": "",
    "authors": [ "" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
        "EntityFramework": "6.1.3",
        "Microsoft.DataAnnotations": "1.0.0-beta1"
    },

    "frameworks": {
        "dnx451": { }
        }
    }
}

或者,使用EntityFramework 7
修改:添加样本以使用EF7
假设您要使用SqlServer和命令生成迁移,您的project.json将是:

{
    "version": "1.0.0-*",
    "description": "",
    "authors": [ "" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
        "EntityFramework.Commands": "7.0.0-beta4",
        "EntityFramework.SqlServer": "7.0.0-beta4",
        "Microsoft.DataAnnotations": "1.0.0-beta1"
    },

    "commands": {
         "ef": "EntityFramework.Commands"
    },

    "frameworks": {
        "dnx451": { }
        "dnxcore50": {
            "dependencies": {
                "System.Collections": "4.0.10-beta-22816",
                "System.Linq": "4.0.0-beta-22816",
                "System.Threading": "4.0.10-beta-22816",
                "Microsoft.CSharp": "4.0.0-beta-22816"
            }
        }
    }
}