This article will guide you on How to install Entity Framework Core. Entity Framework Core can used with .NET Core and .Net Framework 4.6 Web Application. This Framework is not included with .Net Core and .NET Framework. It can be installed using the NuGet package.
To use Entity Framework Core in our projects we need to have the following packages.
- Entity Framework Core Database Provider
- Entity Framework Core Tools
Before we start, please make sure to have Visual Studio installed on your machine. You can download the latest version of Visual Studio through this link.
Let’s start installing EF packages.
I. Entity Framework Core Database Provider
This package will create a connection to the database that our application will be using. This framework will allow us to access and modify databases based on the models we have to create. There are different DB providers. It depends on what database you are using. In this case, we will use SQL Database.
Database Provider:
- SQL Server » Microsoft.EntityFrameworkCore.SqlServer
- MySQL » MySql.Data.EntityFrameworkCore
- To install, open Tools » NuGet Package Manager » Manage NuGet Packages for Solution.
Alternatively, you can right-click on your project from the solution explorer and then select Nuget Package Manager. This option will open the Nuget Manager UI.
2. Once the UI for NuGet Manager is open. Click on browse and search for Microsoft.EntityFrameworkCore.SqlServer. You can refer to the image below.
3. Now, Select Microsoft.EntityFrameworkCore.SqlServer since we are using SQL Server. Click install to start adding the package to your projects. It will show a dialog box that will prompt you the changes to your project.
4. Click on the “OK” button, then Accept the term associated with the package to proceed with the installation.
5. You can verify if the package is installed by going to Dependencies » Packages. See the image below.
Now, we have installed and verified our package installation. Next, we need to install the Entity Framework core tools.
II. Entity Framework Core Tools
These tools will help us execute command related to EF Core tasks, such as migration, update database, scaffolding, etc. This tool is also available in NuGet Package Manager.
- Open NuGet Package Manager and search for Microsoft.EntityFrameworkCore.Tools. Then install the package.
Now, you have successfully installed DB Provider and Entity Framework tools on your web application. We also have an alternative way to install packages on visual studio by using the Package manager console.
Install using Package Manager Console
We can also install the package using the Command line. Open Package Manager Console. As shown below.
This menu will open the Package Manager Console, where you can execute your package installation. See the image below.
Command:
- Install-Package Microsoft.EntityFrameworkCore.SqlServer
- Install-Package Microsoft.EntityFrameworkCore.Tools
If you are using Visual Studio Code, you can perform this dotnet CLI using it’s terminal:
- dotnet add package Microsoft.EntityFrameworkCore.SqlServer
- dotnet add package Microsoft.EntityFrameworkCore.Tools
Summary
We have added Nuget Packages using Package Manager, and we also perform the Package Manager Console command to add packages. This article shows How to install the Entity Framework Core package on your existing Web Application project. Hopefully, this can guide you and help you on your future project. Happy coding!
You may also visit this article on Using Identity in ASP.NET Core Web Application.