This error appears to me. I use .NET 8. The project is divided into three layers. The presentation layer is a web project. The rest of the layers are class libraries. I installed the necessary libraries, all of which are version 8.

saleh salem 20 Reputation points
2024-07-16T20:30:25.5766667+00:00

Screenshot 2024-07-16 232659

Screenshot 2024-07-16 232758

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
729 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,487 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,791 questions
{count} votes

Accepted answer
  1. Ping Ni-MSFT 4,005 Reputation points Microsoft Vendor
    2024-07-17T06:09:58.8733333+00:00

    Hi @saleh salem,

    Your package reference seems to be correct. The error you're encountering indicates that the UseSqlServer method is not being recognized by the DbContextOptionsBuilder. This method is part of the Microsoft.EntityFrameworkCore.SqlServer package.

    1. Try to manually remove all the Bin and Obj directories in the projects. And the package and .vs directories, if you have them.
    2. Then right-click the project to clean and rebuild the project. User's image
    3. If still not working, try to install the two packages again by using Nuget Package Manager or run command in Package Manager Console like below:
    Install-Package Microsoft.EntityFrameworkCore.SqlServer
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Rena

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Michael Taylor 53,146 Reputation points
    2024-07-16T21:21:14.36+00:00

    Quick action the error in the IDE and it'll give you the option(s) needed to fix this problem.

    Also, I would not recommend doing this. In general connection strings and other "static" configuration should be done as part of app startup in your entry point, not here when configuring the context. This method is designed for making any final configuration changes needed before the context is ready to go. Setting connection strings should be done as part of the app startup because they should be stored outside the code. You should probably move this call into where you're calling AddDbContext which is where it normally occurs.

    1 person found this answer helpful.
    0 comments No comments

  2. SurferOnWww 2,581 Reputation points
    2024-07-17T08:34:43.1766667+00:00

    I suggest that you create ASP.NET Core MVC app according to the following tutorial:

    Get started with ASP.NET Core MVC

    Do not skip Part 1 through Part 4.

    At the Scaffold movie pages section of Part 4, add a model to an ASP.NET Core MVC app,

    Scaffolding adds the following packages:

    • Microsoft.EntityFrameworkCore.SqlServer
    • Microsoft.EntityFrameworkCore.Tools
    • Microsoft.VisualStudio.Web.CodeGeneration.Design

    Scaffolding creates the following:

    • A movies controller: Controllers/MoviesController.cs
    • Razor view files for Create, Delete, Details, Edit, and Index pages: Views/Movies/*.cshtml
    • A database context class: Data/MvcMovieContext.cs

    Scaffolding updates the following:

    • Inserts required package references in the MvcMovie.csproj project file.
    • Registers the database context in the Program.cs file.
    • Adds a database connection string to the appsettings.json file.

    The automatic creation of these files and file updates is known as scaffolding.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.