升级到EF 7.0.0-rc1-final后,SQL DbContextOptionsBuilder UseSqlServer出现故障。

5

我刚刚将我的nuget包更新到EF 7.0.0-rc1-final版本,从之前的EF 7版本。这个更新破坏了我的SQL连接字符串代码。

using System.Collections.Generic;
using ComicEndpoints.Models;
using System.Threading.Tasks;
using Microsoft.Data.Entity;
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
    options.UseSqlServer(@"ConnectionString");
}

错误信息:

类型 'DbContextOptionsBuilder' 是在一个未被引用的程序集中定义的。 您必须添加对程序集 'EntityFramework.Core, Version 7.0.0.0' 的引用。

我已经在NuGet中安装了最新版本的EntityFramework.Core,但是在使用'using'时无法引用它。这个问题只发生在我升级到rc1-final之后,我无法找到任何文档涉及这种变化。 project.JSON
{
  "webroot": "wwwroot",
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "EntityFramework.SqlServer": "7.0.0-beta8",
    "EntityFramework.SqlServer.Design": "7.0.0-beta8",
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
    "Newtonsoft.Json": "8.0.1-beta2",
    "EntityFramework.Core": "7.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --config hosting.ini",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "Microsoft.AspNet.WebApi.Cors": "5.2.3",
        "Microsoft.Owin.Cors": "3.0.1"
      }
    },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],
  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ]
}

1
你应该在问题中发布你的project.json文件。 - Joe Audette
1
你还没有更新所有的东西,有些东西你还停留在beta8版本。 - Joe Audette
需要将"Microsoft.Framework.Configuration.Json"重命名为"Microsoft.Extensions.Configuration.Json"才能获得rc1-final版本。 - Joe Audette
1
每当引入新的破坏性API更改时,Visual Studio工具并没有清晰地表明需要更新所有相关程序集,这真的很糟糕。我认为整个ASP.net beta项目对于我作为消费者以及作为生产者制作这些工具的开发人员来说,都是一个非常好的版本控制教育。 - Warren P
3个回答

15

我相信它的名字也已经改变了:

'EntityFramework.SqlServer': "7.0.0-rc1-final'

-- 现在是:

'EntityFramework.MicrosoftSqlServer': "7.0.0-rc1-final'

参见文章:将ASP.NET 5 Beta 8升级到RC1

提示:从GitHub下载Asp.Net文档并查看它们(ASP.NET作者)如何编写引用和依赖关系...


3
我曾安装了beta和rc1版本,删除它们有所帮助。 - matthewdaniel

1

你需要将所有内容更新至rc1版本

"Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"EntityFramework.SqlServer": "7.0.0-rc1-final",
"EntityFramework.SqlServer.Design": "7.0.0-rc1-final",
"EntityFramework.Commands": "7.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Newtonsoft.Json": "8.0.1-beta2",
"EntityFramework.Core": "7.0.0-rc1-final"

我也对你在dnx451下的依赖关系是否合法或必要感到怀疑。


您的网页命令需要更新为“web”:”Microsoft.AspNet.Server.Kestrel”。 - Joe Audette

1
EntityFramework.SqlServer 替换为 EntityFramework.MicrosoftSqlServer 即可。
请参考此博客文章 将ASP.NET 5 Beta 8升级到RC1
  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.Core": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.Relational": "7.0.0-rc1-final"
  },

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接