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 2017.

create asp net core application

Next select .NET Core & ASP.NET Core 2.0 from the options.

select asp.net core 2.0 framework

For the project template select Web Application (Model-View-Controller), and click the OK button.

Now you are ready to Install Entity Framework Core on your application.

Install EF Core using NuGet Package

There are 2 things to install here:

  • EF Core DB provider
  • EF Core tools

Install EF Core DB Providers

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 Go to Tools > NuGet Package Manager > Package Manager Console and execute the command PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer.

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. Package Manager Console
  • 2. dotnet CLI

Install Package Manager Console

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

install EF Core Tools

Install dotnet CLI

Installation of dotnet CLI is done in a different manner. Right click on the Project in the solution explorer and select Edit ‘YourSolution.csproj’.

edit project in solution explorer

The project file will open on the editor. You have to add the below lines to it.

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" />
</ItemGroup>

This will install the dotnet CLI.

installing dotnet cli

Now open the package manager console (Tools > NuGet Package Manager > Package Manager Console) and enter dotnet ef command.

PM> dotnet ef

You will see a horse picture telling the dotnet CLI has been installed successfully.

dotnet ef command

The dotnet ef command should be executed from the directory of the project.csproj file. To move inside a directory use cd directoryname. To move to the outer directory use cd .\directoryname.

DOWNLOAD

Share this article -

yogihosting

ABOUT THE AUTHOR

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