In this tutorial you will learn How to Install Entity Framework Core on your project.
First create a new web app in Visual Studio by selecting ASP.NET Core Web App (Model-View-Controller) template. See the image below.
To this app we will Install Entity Framework Core and work on database operations.
Entity Framework Core has Database Providers for all major databases. The installation of each of them can be done through NuGet. Here we will install SQL Server database provider since we will be working on a SQL Server Database.
In 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.
The package will show up. Click on it, then on the right side check the checkbox given against the project and click the Install button.
The installation of the package will start and we will see Preview Changes window. Click the OK button.
Next we 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 the app.
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. For this we will need “any” of the two tools. These tools are:
Let us understand their installation procedures.
First open Package Manager Console window from Tools ➤ NuGet Package Manager ➤ Package Manager Console menu. Then run the following command to install it.
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. Check the below image.
Verify the installation by running the following command in Package Manager Console.
It will show the horse images along with different commands and their work.
We learned how to perform the installation of SqlServer database provider package and EF Core tools in the app. Now it’s time to understand the workings of EF Core. Check the next tutorial whose link is given below and proceed.