ASP.net vNext 和 Entity Framework 6

ASP.net vNext and Entity Framework 6

预发布 ASP.net vNext 下是否可以 运行 EF6? EF7 没有我需要的一些功能,但我想在 .NET Core 中制作我的应用程序原型。

我收到以下错误:

FileLoadException: A strongly-named assembly is required. 
(Exception from HRESULT: 0x80131044) Unknown location

FileLoadException: Could not load file or assembly
'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' or one of its dependencies. 
A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)

我知道 .NET Core 不支持强命名程序集,但据我所知,我运行在 aspnet50 框架而不是 aspnetcore50 下安装服务器。

我的 project.json 看起来像这样:

{
    "webroot": "wwwroot",
    "version": "1.0.0-*",
    "dependencies": {
        "EntityFramework": "6.1.1",
        "Microsoft.AspNet.Mvc": "6.0.0-beta3",
        /* "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-beta3", */
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta3",
        "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta3",
        "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta3",
        "Microsoft.AspNet.Security.Cookies": "1.0.0-beta3",
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta3",
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta3",
        "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta3",
        "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta3",
        "Microsoft.Framework.Logging": "1.0.0-beta3",
        "Microsoft.Framework.Logging.Console": "1.0.0-beta3",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta3",
        "Tricycle.SqlPlatform.EntityFramework": "1.0.0-*"
    },
    "commands": {
        /* Change the port number when you are self hosting this application */
        "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
        "gen": "Microsoft.Framework.CodeGeneration",
    },
    "frameworks": {
        "aspnet50": {
            "dependencies": {
                "Tricycle.Studio.ContentManager.Client": "1.0.0-*"
            }
        },
        //"aspnetcore50": { }
    },
    "exclude": [
        "wwwroot",
        "node_modules",
        "bower_components"
    ],
    "bundleExclude": [
        "node_modules",
        "bower_components",
        "**.kproj",
        "**.user",
        "**.vspscc"
    ],
    "scripts": {
        "postrestore": [ "npm install" ],
        "prepare": [ "grunt bower:install" ]
    }
}

EF 类 在单独的项目 (Tricycle.Studio.ContentManager.Client) 中定义,具有以下 project.json:

{
    "version": "1.0.0-*",
    "dependencies": {
        "EntityFramework": "6.1.1",
    },

    "frameworks": {
        "aspnet50": {
            "dependencies": {
                "System.Data.Common": "1.0.0-beta2",
                "System.Data.SqlClient": "1.0.0-beta2"
            }
        },
        //"aspnetcore50" : {
        //    "dependencies": {
        //        "System.Runtime": "4.0.20-beta-22523"
        //    }
        //}
    }
}

您不能将 Microsoft.AspNet.Identity.EntityFramework 与 EF6 一起使用,因为它依赖于 EF7。

根据您的 project.json 文件,运行时将加载 EF6 和 EF7(因为身份)。行为是不可预测的。

另外,不要混用 beta2beta3 包。那肯定有麻烦。