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 ASP.NET Core Web Application in Visual Studio as shown by the image below.

create asp.net core application

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.

configure application

Next select .NET Core & ASP.NET Core 3.1 from the options (check below image).

select asp.net core 2.0 framework

Finally click the Create button. Now you are ready to Install Entity Framework Core on your application.

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 using NuGet Package

There are 2 things to install here:

  • EF Core DB provider – I will be using SQL Server so I will install EF Core SQL Server provider.
  • EF Core tools – These are of 2 types – .NET Core command-line interface (CLI) tools & Package Manager Console (PMC) tools.

Install EF Core SQL Server Provider

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.

open nuget

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.

install Microsoft.EntityFrameworkCore.SqlServer

The installation will start and you will see Preview Changes window. Click the OK button.

preview changes window

Next you 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 your project.

You can verify it by seeing the Dependencies > NuGet section of your Solution Explorer.

dependencies nuget section
Alternatively, go to Tools > NuGet Package Manager > Package Manager Console in Visual Studio, and execute the command PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer.
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 EF Core Tools

There are many EF Core commands like Migration, scaffoldings that needs to be executed. We use 2 tools to execute them. These are:

  • 1. .NET Core command-line interface (CLI) tools
  • 2. Package Manager Console (PMC) tools

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

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

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

2. Install Package Manager Console (PMC) tools

Go to NuGet UI and search for Microsoft.EntityFrameworkCore.Tools, and install it (i.e the first one).

install EF Core Tools

You can download the full codes of this tutorial from the below link:

DOWNLOAD

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

Share this article -

yogihosting

ABOUT THE AUTHOR

This article has been written by the Technical Staff of YogiHosting. Check out other articles on "ASP.NET Core, jQuery, EF Core, SEO, jQuery, HTML" and more.