简体   繁体   中英

Ambiguous invocation of SqlServerDbContextOptionsBuilder after upgrade to AspNet 5 RC1-update1

I want to upgrade my project from asp.net beta-7 to asp.net 5 RC1-update-1 but I'm getting to two errors in my startup.cs at:

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"]));
}

First Visual Studio tells me the DbContextOptionsBuilder type is defined in a not referenced assembly. In this case the reference is EntityFramework.Core version 7.0.0.0 and is referenced

Second there seems to be an ambiguous invocation:

Ambiguos invocation:

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

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

My 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" ]
}
}

You do seem to have a duplicated entry in jour project.json , althouhg it is not immediately obvious because the dll names have changed:

what used to be "EntityFramework.SqlServer" is now: "EntityFramework.MicrosoftSqlServer"

So just remove the line

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

and you should be good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM