升级到AspNet 5 RC1-update1后,SqlServerDbContextOptionsBuilder的模糊调用

时间:2015-12-04 12:00:27

标签: c# asp.net entity-framework

我想将我的项目从asp.net beta-7升级到asp.net 5 RC1-update-1,但我在startup.cs处遇到两个错误:

public void ConfigureServices(IServiceCollection services)
{
   // Add Entity Framework services to the services container.
   services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext<ApplicationDbContext>(options =>
           options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
}

第一个Visual Studio告诉我DbContextOptionsBuilder类型是在未引用的程序集中定义的。在这种情况下,引用为EntityFramework.Core version 7.0.0.0引用

其次,似乎存在模糊的调用:

Ambiguos调用:

Microsoft.Data.Entity.Infrastructure.SqlServerDbContextOptionsBuilder.UseSqlServer(
this Microsoft.Data.Entity.SqlServerDbContextOptionsBuilder, string)

Microsoft.Data.Entity.SqlServerDbContextOptionsBuilder.UseSqlServer(
this Microsoft.Data.Entity.SqlServerDbContextOptionsBuilder, string)

我的project.json:

{
"webroot": "wwwroot",
"userSecretsId": "--removed--",
"version": "1.0.0-*",

"dependencies": {
    "EntityFramework.Core": "7.0.0-rc1-final",
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.SqlServer": "7.0.0-beta7",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final"
},

"commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
},

"frameworks": {
    "dnx451": { },
    "dnxcore50": { }
},

"exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
],
"publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
],
"scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
}

1 个答案:

答案 0 :(得分:1)

你似乎在jour project.json中有一个重复的条目,但是由于dll名称已经改变,所以它并不是很明显:

以前的"EntityFramework.SqlServer"现在是:"EntityFramework.MicrosoftSqlServer"

所以只需删除

"EntityFramework.SqlServer": "7.0.0-beta7",

你应该好好去。