efcore: UseSqlServer() method is missing from Microsoft.EntityFrameworkCore.SqlServer 1.1.1

While following the Identity4 tutorial, it seems the DbContextOptionsBuilder.UseSqlServer() method is missing. Was this moved to a new package?

error

Exception message: 
'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer' and no extension method 'UseSqlServer' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?)

Steps to reproduce

services.AddIdentityServer()
                .AddTemporarySigningCredential()
                .AddTestUsers(Config.GetUsers())
                .AddConfigurationStore(builder =>
                    builder.UseSqlServer(connectionString, options => 
                        options.MigrationsAssembly(migrationsAssembly)))
                .AddOperationalStore(builder =>
                    builder.UseSqlServer(connectionString, options =>
                        options.MigrationsAssembly(migrationsAssembly)));

Further technical details

EF Core version: 1.1.1 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 10 IDE: Visual Studio 2017

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 44 (5 by maintainers)

Most upvoted comments

Hm - try manually adding the using statement using Microsoft.EntityFrameworkCore; and building again. It could be a Roslyn-related issue.

If you can post it on GitHub, I don’t mind checking it out

Okay so adding this manually isn’t working for me. It says that the using directive is unnecessary.

Edit: Installing the NuGet package “Microsoft.EntityFrameworkCore.SqlServer” fixed this for me, my bad.
Will leave this comment here for anyone else that makes this (stupid) mistake. Thanks.

Manually installing the NuGet-package “Microsoft.EntityFrameworkCore.SqlServer” fixed it for me as well - cheers, @Braed!

Thanks, adding the using did solve it

Just realized this myself. Now it’s here to read as well for the next hapless fool 😃

dotnet add package Microsoft.EntityFrameworkCore.SqlServer and off you go

Incorrect package

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />

You need reference to Microsoft.EntityFrameworkCore.SqlServer EFCore is just core package. You need to reference provider specific package.

It looks like UseSqlServer is now under ConfigureDbContext in AddConfigurationStore.

Code snippet:

services.AddIdentityServer()
 .AddConfigurationStore(opt => opt.ConfigureDbContext = builder => builder.UseSqlServer(AuthorizationConnectionString, options => options.MigrationsAssembly(migrationsAssembly)))
.AddOperationalStore(opt => opt.ConfigureDbContext = builder => builder.UseSqlServer(AuthorizationConnectionString, options => options.MigrationsAssembly(migrationsAssembly)));

remove the follow refs from the csproj file, <PackageReference Include="Microsoft.VisualStudio.Web.CodeGenerators.Mvc" Version="1.1.0-preview4-final" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="1.1.0-preview4-final" /> <PackageReferenceInclude="Microsoft.VisualStudio.Web.CodeGeneration"Version="1.1.0-preview4-final" />

Add the following refs, <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0-msbuild3-final" /> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" /> Source: https://developercommunity.visualstudio.com/content/problem/10914/scaffolding-net-core-with-entity-framework.html

install the Microsoft.EntityFrameworkCore.SqlServer nugget package manually and Try using Microsoft.EntityFrameworkCore; ->worked

yes, adding using Microsoft.EntityFrameworkCore; solved the problem

Thanks guys…

I had same issue, to resolve this i had to Install Microsoft.EntityFrameworkCore.SqlServer package separately then use using Microsoft.EntityFrameworkCore.SqlServer;

At first, the project did not build and those errors appeared in the Error List. After I restarted Visual Studio, the build no longer failed, but it still stated that the UseSqlServer() extension method could not be found.

I am using .Net Core 3.0 and install this package Microsoft.EntityFrameworkCore.SqlServer still giving me the same error.

Installing the following packages resolves the problem. Use the compatibility version. No need for using statements:

Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer

I had it when i started with a mvc auth project. I noticed that it put SQL LITE references into the project and maybe it caused this issue, as a conflict against SQL SERVER.

To fix it i removed all SQL LITE library references, and after that i installed SQL SERVER reference:

dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 2.0.0

It works for me, i wish that it can be helpful!

Try using Microsoft.EntityFrameworkCore;

Installing Microsoft.EntityFrameworkCore.SqlServer solved the problem for me. It is strange that the installed package is showing unused in the file, but it is not showing any error now and build is successful.

just at the moment had the same problem , after verifing the Msdn link UseSqlServer found that the Microsoft.EntityFrameworkCore has not added the Microsoft.EntityFrameworkCore.SqlServer

@rwobben I don’t believe the **.CodeGeneration packages are related to this issue. The issue seems to have resolved itself. Try updating VS2017 (Tools -> Extensions and Updates -> Updates), updating the Microsoft.EntityFrameworkCore.SqlServer package, and restarting Visual Studio.

Update VS2017

Hm - try manually adding the using statement using Microsoft.EntityFrameworkCore; and building again. It could be a Roslyn-related issue.

If you can post it on GitHub, I don’t mind checking it out

it is working for me

Install for nugget:

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.5

Fonte: https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer/

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.3

Adding using solved for me as well. Ah ah.