In this tutorial you will learn How to Install Entity Framework Core on your project.
First create a new ASP.NET Core Web Application in Visual Studio as shown by the image below.
Specify the location on your drive where you want the application to be created and give it some name of your choice. Check the given below image.
Next select .NET Core & ASP.NET Core 3.1 from the options (check below image).
Finally click the Create button. Now you are ready to Install Entity Framework Core on your application.
There are 2 things to install here:
EF Core has DB providers of all major databases. The installation of each of them is done through NuGet. Here I will tell you how to install DB provider for SQL Server database.
In your Visual Studio go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution, this will open the NuGet UI.
Here click the Browse link and search for Microsoft.EntityFrameworkCore.SqlServer on the text box.
It will show up on the results below the search box. Click on it, then on the right side check the checkbox given against the project.
Finally click the Install button.
The installation will start and you will see Preview Changes window. Click the OK button.
Next you will see the License Acceptance window, click the I Accept button.
Within few seconds the installation procedure will complete and the Microsoft.EntityFrameworkCore.SqlServer provider will be installed on your project.
You can verify it by seeing the Dependencies > NuGet section of your Solution Explorer.
There are many EF Core commands like Migration, scaffoldings that needs to be executed. We use 2 tools to execute them. These are:
First open Package Manager Console window (Tools ➤ NuGet Package Manager ➤ Package Manager Console) then install dotnet ef by running the following command.
dotnet tool install --global dotnet-ef
Worth Mentioning – If you already had dotnet ef installed in your pc then it should be updated to the latest version. Run the following update command to do this job.
dotnet tool update --global dotnet-ef
Next, install the Microsoft.EntityFrameworkCore.Design package by running the following command on the Package Manager Console window.
dotnet add package Microsoft.EntityFrameworkCore.Design
Test the packages by running the following command on Package Manager Console.
PM> dotnet ef
You will see a horse picture telling the dotnet CLI has been installed successfully.
Go to NuGet UI and search for Microsoft.EntityFrameworkCore.Tools, and install it (i.e the first one).
You can download the full codes of this tutorial from the below link: