In this tutorial, we will show you how to install the Entity Framework Core.
Table of Contents
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.
- Using Package Manager GUI Tools
- Package Manager Console
- Command Line
- 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
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.
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
Select the Project, where you want to install the package. Use the Install-Package <PackageName>
to install the package
Run the following commands. This will install the latest available version
1 2 3 | Install-Package Microsoft.EntityFrameworkCore.SqlServer |
1 2 3 | Install-Package Microsoft.EntityFrameworkcore.Tools |
Use the -Version
flag to install the previous version
1 2 3 | Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.10 |
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
1 2 3 | dotnet add package Microsoft.EntityFrameworkCore.SqlServer |
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.
1 2 3 | dotnet add TestProj package Microsoft.EntityFrameworkCore.SqlServer |
Use the -v
flag to choose the version.
1 2 3 4 | dotnet add TestProj.csproj package icrosoft.EntityFrameworkCore.SqlServer -v 3.1.10 |
Modify the Project file
Right-click on the project and click on edit project file.
Update the project and add the PackageReference
under ItemGroup
node
1 2 3 4 5 6 7 8 9 10 | <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> </ItemGroup> |
References
.NET implementations supported by EF Core
Read More