ASP.net vNext和实体框架6

时间:2015-03-17 16:59:56

标签: asp.net entity-framework asp.net-core

是否可以在预发布的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"
        //    }
        //}
    }
}

1 个答案:

答案 0 :(得分:9)

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

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

此外,请勿混用beta2beta3个软件包。这确保了麻烦。