Install Entity Framework Core

Here we will install Entity Framework Core 7 in the .NET 7 (also known as .NET Core 7) console application. EF Core 7 is the latest version of Entity Framework as of this writing. You can install EF Core 6.0 which has a long term support in the same way.

EF Core 6/7 is not included as a default package in .NET 7. We need to install it via the NuGet package.

The Microsoft.EntityFrameworkCore is the base package for all the basic operations of EF Core. However, you have to install a database provider package from NuGet for the database you use in your project. For example, to use the MS SQL Server database, you need to install Microsoft.EntityframeworkCore.SqlServer package.

The database provider package of EF Core includes all the other dependent packages it needs. So, it includes Microsoft.EntityFrameworkCore too. So, no need to install it separately.

EF Core supports the following database providers.

Here we will use the local SQL Server database in the following .NET 7 console application, so we will install the Microsoft.EntityframeworkCore.SqlServer NuGet package. If you use different database, then you can install related NuGet package in the same way.

Install EF Core

You can install EF Core NuGet package in your project using the following ways:

  1. Using NuGet Package Manager
  2. Using Package Manager Console
  3. Using DotNet CLI
  4. Using PowerShell
  5. Adding package reference directly in .csproj

Install EF Core using NuGet Package Manager

To install EF Core 6/7 package using NPM, go to the Project menu and click on “Manage NuGet Packages..”.

This will open Nuget Package Manager, as shown below.

Install EF Core using NPM

Click on the Browser tab and search for "entityframeworkcore" in the search box. It will display all the packages related to EF Core, as shown below.

Install EF Core using NPM

We are going to use SQL Server for our project, so select the Microsoft.EntityFrameworkCore.SqlServer package and click on the Install button in the right pane.

Install EF Core using NPM

Accept the license agreement to install the package in your project. Once installed, you will see the package is listed as a dependency package in the solution explorer, as shown below.

Install EF Core using NPM

You can also see it in the .csproj file by double-clicking on your project name “EFCoreTutorialsConsole”.

Install EF Core using NPM

Install EF Core Using Package Manager Console

EF Core 6/7 can also be installed using Package Manager Console. To open the Package Manager Console. Go to Tools > NuGet Package Manager > Package Manager Console.

This will open the package manager console, as shown below.

Package Manager Console

Use the Install-Package command followed by the package name to install any NuGet package in your project. Make sure that it points to a project where you want to install the project.

To install the EF Core database provider for SQL Server, execute the following command:

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 7.0.11
Install EF Core using PMC

This will install EF Core SQL Server provider and all its dependencies to your project.

Install EF Core Using .NET CLI

To install EF Core using the .NET CLI (Command Line Interface), open your terminal or command prompt and navigate to your project directory. This should be the directory that contains your project's .csproj file.

Install the EF Core package for SQL Server using the following command.

dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 7.0.11

This will install the package in your project.

Install EF Core Using PowerShell

To install EF Core DB provider for SQL Server, open the PowerShell terminal in Visual Studio 2022 by right-clicking on the project and clicking “Open Terminal” from the context menu. It will point to your project directory by default, as shown below.

Install EF Core using PowerShell

You can use .NET CLI command here. Use the dotnet add package command to install any NuGet package in your project. To install EF Core DB provider for SQL Server, execute the following command.

dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 7.0.11

This will install the package in your project.

Adding Package Reference in .csproj

You can simply add the package reference in your .csproj file. Double-click on your project name in Visual Studio to open .csproj file.

Now, add an ItemGroup element after PropertyGroup. In the ItemGroup element, add a PackageReference element and specify the PackageId as "Microsoft.EntityFrameworkCore.SqlServer" and specify the Version attribute to the desired version, in this case "7.0.11", as shown below.

Add EF Core Reference in .csproj

Save the file and you will see that the package is automatically added to your project dependencies.

Thus, you can install EF Core package in different ways as per your convenience.

After installing EF Core DB provider for SQL Server, let’s create entities next.