Installation of Entity Framework Core

Installation of Entity Framework Core

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.

create asp.net core mvc application

To this app we will Install Entity Framework Core and work on database operations.

If you are just a beginner then check out my article on Introduction to ASP.NET Core MVC which is made specially for beginners.

Install EF Core SQL Server Provider

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.

open nuget

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.

install Microsoft.EntityFrameworkCore.SqlServer

The installation of the package will start and we will see Preview Changes window. Click the OK button.

preview changes window

Next we will see the License Acceptance window, click the I Accept button.

license acceptance

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.

Alternatively, go to Tools > NuGet Package Manager > Package Manager Console in Visual Studio, and execute the command PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer. This will install the SqlServer package of Entity Framework Core on the app.
EF Core is made on top of ADO.NET. I have also written a complete series on ADO.NET which you can start from Learn ADO.NET by building CRUD features in ASP.NET Core Application

Install Entity Framework Core Tools

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:

  • 1. .NET Core command-line interface (CLI) tools: it can be used on Windows, Linux, or macOS. Their commands begin with “dotnet ef”.
  • 2. Package Manager Console (PMC) tools: it can be used only on Visual Studio on Windows. These commands start with a verb, for example “Add-Migration”, “Update-Database”, etc.

Let us understand their installation procedures.

.NET Core command-line interface (CLI) tools

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 from NuGet.

install Microsoft.EntityFrameworkCore.Design

Test

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.

dotnet ef command Install .NET Core command-line interface (CLI) tools

We can also use the following .NET Core CLI command to install the EF Core SQL Server provider.

dotnet add package Microsoft.EntityFrameworkCore.SqlServer

Package Manager Console (PMC) tools

Go to NuGet UI and search for Microsoft.EntityFrameworkCore.Tools, and install it. Check the below image.

Install Package Manager Console (PMC) tools

Alternately, we can also run the following install command in the Package Manager Console.

Install-Package Microsoft.EntityFrameworkCore.Tools

Verify the installation by running the following command in Package Manager Console.

Get-Help about_EntityFrameworkCore

It will show the horse images along with different commands and their work.

We can also use the following Package Manager Console (PMC) command to install the EF Core SQL Server provider.

Install-Package Microsoft.EntityFrameworkCore.SqlServer
Conclusion

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.

Next tutorial – You are now read to learn EF Core – Datatbase First approach

SHARE THIS ARTICLE

  • linkedin
  • reddit
yogihosting

ABOUT THE AUTHOR

I hope you enjoyed reading this tutorial. If it helped you then consider buying a cup of coffee for me. This will help me in writing more such good tutorials for the readers. Thank you. Buy Me A Coffee donate