DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer' and no accessible extension method. 'UseSqlServer' accepting a first argument of type 'DbContextOptionBuilder' could be found ( are you missing a using directive or an assemply reference)
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I'd like to thank those who replied, but I can't run the scaffolding procedure because in the Program.cs file error:
CreateWebHostBuilder does not exist in the current context.
It's not real clear how you got to this point. Delete the project and start over or download the completed project and compare the difference to your code.
Member
2 Points
16 Posts
Contoso University - DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer'
May 14, 2020 04:30 PM|Geol4549|LINK
I am trying to work through the Contoso University example application. I have simply copied the Startup.cs class statements:
services.AddDbContext<SchoolContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
I receive the error:
DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer' and no accessible extension method. 'UseSqlServer' accepting a first argument of type 'DbContextOptionBuilder' could be found ( are you missing a using directive or an assemply reference)
What do I need to do to move forward?
Thanks
All-Star
53711 Points
24036 Posts
Re: Contoso University - DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer...
May 14, 2020 06:53 PM|mgebhard|LINK
You missed a the scaffolding step. This step creates adds the required packages, connection string, and updates the startup.cs file.
https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-3.1&tabs=visual-studio#scaffold-student-pages
Contributor
2720 Points
874 Posts
Re: Contoso University - DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer...
May 15, 2020 01:44 AM|Rena Ni|LINK
Hi Geol4549,
Add the reference like below:
Best Regards,
Rena
Member
10 Points
13 Posts
Re: Contoso University - DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer...
May 15, 2020 02:47 AM|Tsaisoul|LINK
Hi Geol4549,
Thanks for your question,
The following maybe a solution:
If you use the EF Core, you must add ' Microsoft.EntityFrameworkCore.SqlServer ' to your reference,
and then don't forget to apply ' using Microsoft.EntityFrameworkCore ' to source file.
Best regards,
Tsaisoul.
Member
2 Points
16 Posts
Re: Contoso University - DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer...
May 15, 2020 08:53 PM|Geol4549|LINK
I'd like to thank those who replied, but I can't run the scaffolding procedure because in the Program.cs file error:
CreateWebHostBuilder does not exist in the current context.
All-Star
53711 Points
24036 Posts
Re: Contoso University - DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer...
May 16, 2020 06:44 AM|mgebhard|LINK
It's not real clear how you got to this point. Delete the project and start over or download the completed project and compare the difference to your code.
Member
2 Points
16 Posts
Re: Contoso University - DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer...
May 16, 2020 01:48 PM|Geol4549|LINK
Thank you for your response. I did delete the project and start over.