I'm trying to implement microservices in .NET core framework (version 6.0) and facing this particular issue while adding the services of DBContext in the Program.CS file.
statement I'm using :
builder.Services.AddDbContext<ProductContext>(options=>options.UseSqlServer(builder.Configuration.GetConnectionString("ProductDB")));
Error CS1061 'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer' and no accessible extension method 'UseSqlServer' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?) Micro D:\NET_Micro\Micro\Micro\Program.cs 7 Active
CodePudding user response:
These Errors occur usually when you are not including certain packages in your code. Try downloading the following NuGet packages by running below mentioned code in your visual studio's package manager console :
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Design
and include them in your startup.cs/program.cs :
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer;
using Microsoft.EntityFrameworkCore.Design;
CodePudding user response:
Try to install the Microsoft.EntityFrameworkCore.SqlServer NuGet Package.
Then, import the namespace with
using Microsoft.EntityFrameworkCore;