Entity Framework Core: DbContextOptionsBuilder does not contain a definition for 'usesqlserver' and no extension method 'usesqlserver'
First we install the Microsoft.EntityFrameworkCore.SqlServer NuGet Package:
PM > Install-Package Microsoft.EntityFrameworkCore.SqlServer
Then, after importing the namespace with
using Microsoft.EntityFrameworkCore;
we add the database context:
services.AddDbContext<AspDbContext>(options =>
options.UseSqlServer(config.GetConnectionString("optimumDB")));
adding
using Microsoft.EntityFrameworkCore;
manually solved the problem for me
Found that here
Edit...
for dotnet core 3.1 add
Microsoft.EntityFrameworkCore.SqlServer
Install below NuGet Package will solve your issue
Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Follow the steps below.
Install Entity Framework Core Design and SQL Server database provider for Entity Framework Core:
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
Import Entity Framework Core:
using Microsoft.EntityFrameworkCore;
And configure your DbContext:
var connectionString = Configuration.GetConnectionString("myDb");
services.AddDbContext<MyDbContext>(options =>
options.UseSqlServer(connectionString)
);
This is a known issue in the project system. See dotnet/project-system#1741