Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

DBContextBuilder doesnot contain a definition for UseSqlServer in .NET 6

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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;


Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading