How to Install Entity Framework Core

In this tutorial, we will show you how to install the Entity Framework Core.

Supported Frameworks

Before installing it is important to know how EF Core is supported in various frameworks. EF Core 6.0 supports only .NET. You can use version 3.1 with the .NET Framework. Learn more about .NET Vs .NET Core Vs .NET Framework

EF Core 8.0. .NET 8

EF Core 7.0. .NET 6

EF Core 6.0. .NET 6

EF Core 5.0. .NET Standard 2.1 & .NET Core 3.0

EF Core 3.1 .NET Standard 2.0 & NET Core 2.0

FF Core 2.1 .NET Standard 2.0 & NET Core 2.0

What to Install

The Microsoft.EntityFrameworkCore is the core library. But installing that alone is not sufficient. We also need to install the EF Core database provider(s). For Example, to use the SQL Server, we need to install the Microsoft.EntityFrameworkCore.SqlServer. For SQLite install the Microsoft.EntityFrameworkCore.Sqlite. When we install the database provider(s), they automatically install the Microsoft.EntityFrameworkCore.

The following are some of the database provider(s)

  • Microsoft.EntityFrameworkCore.InMemory
  • Npgsql.EntityFrameworkCore.PostgreSQL
  • Pomelo.EntityFrameworkCore.MySql (for both Mysql & MariaDB)
  • MySql.Data.EntityFrameworkCore (Official version for MySQL)
  • Oracle.EntityFrameworkCore
  • EntityFrameworkCore.Jet (Microsoft Access)

We also need to install the Entity Framework Core tools. These tools contain tools that help us to create migrations, apply migrations, and generate code for a model based on an existing database. The tools are available in the package Microsoft.EntityFrameworkCore.Tools.

Various Ways to Install Entity Framework Core

We can install Entity Framework Core in several ways.

  1. Using Package Manager GUI Tools
  2. Package Manager Console
  3. Command Line
  4. Modify the Project file

Using Package Manager GUI Tools

In Visual Studio go to Tools menu select NuGet Package Manager -> Manage NuGet Packages for Solution.

You can also right-click on the Solution in the Solution Explorer and select Manage NuGet Packages for Solution

Manage Nuget Packages for Solutions

Under Browse tab search for the Microsoft.EntityFrameworkCore.SqlServer Package. Select the package to install. On the right-hand side, select the projects to which you want to add the package. Also, choose the version and click on Install to begin the installation.

Installing Microsoft.EntityFrameworkCore Package from Package Manager

Installation will you to accept the license terms. Select accept to complete the installation.

Install Entity Framework Core Tools

Search for Microsoft.EntityFrameworkCore.Tools in the package manager and repeat the above steps to install the tools.

Package Manager Console

Open the Package Manager Console from the tools -> NuGet Package Manager -> Package Manager Console

Installing Entity Framework Core using Package manager console

Select the Project, where you want to install the package. Use the Install-Package <PackageName> to install the package

Package manager console

Run the following commands. This will install the latest available version

Use the -Version flag to install the previous version

Dot Net Command Line

Using the .NET Core CLI command dotnet add package is another way to install the Entity Framework Core

Open the command prompt and cd into the project folder (folder with .csproj file). Run the following command

Specify the name of the project after the add option to install only in that project. This is useful when you have multiple projects in your solution.

Use the -v flag to choose the version.

Modify the Project file

Right-click on the project and click on edit project file.

Editing Project file to install entity framework core

Update the project and add the PackageReference under ItemGroup node

References

.NET implementations supported by EF Core

Read More

  1. Entity Framework Core Tutorial
  2. Entity Framework Core Console Application
  3. EF Core Migrations
  4. ASP.NET Core Tutorial

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top