• Home
  • About
  • Contact
  • ado.net
  • angular
  • c#.net
  • design patterns
  • linq
  • mvc
  • .net core
    • .Net Core MVC
    • Blazor Tutorials
  • sql
  • web api
  • dotnet
    • SOLID Principles
    • Entity Framework
    • C#.NET Programs and Algorithms
  • Others
    • C# Interview Questions
    • SQL Server Questions
    • ASP.NET Questions
    • MVC Questions
    • Web API Questions
    • .Net Core Questions
    • Data Structures and Algorithms

Saturday, August 22, 2020

How to Install Entity Framework Core

 Admin     August 22, 2020     .Net, .Net Core, C#, Entity Framework, Entity Framework Core     No comments   

In this article, I am going to discuss How to Install Entity Framework Core in Visual Studio step by step in different types of applications. Please read our previous article where we discussed the introduction part of Entity Framework Core.

Note: The Entity Framework Core can be used with .NET Core applications as well as .NET 4.6 based applications. Here, in this article, I will show you how to install EF Core in .NET Core applications using Visual Studio 2017.

The Entity Framework Core is not a part of .NET Core and standard .NET framework. It is available as a NuGet package. Depending on how you have set your project, you may have already installed the Entity Framework Core.

Depending on the project complexity or requirement, you can develop a web application as:
  1. Single Layer Web Application
  2. Multi-Layer Web Application
Single Layer Web Application
When you develop a small project, then you may have the presentation, business, and data access layer all in one project. So when we created a web application project using ASP.NET Core 2.1 or higher, then by default the Entity Framework Core already installed.

Entity Framework Core in ASP.NET Core Web Application Project
When we create an ASP.NET Core Web application using ASP.NET Core 2.1 or higher version, then by default the following NuGet package installed.

Microsoft.AspNetCore.App

The above package is called a Meta package. A Meta package does not hold any content of its own rather it holds a list of other packages. You can find this Meta package, in the Solution Explorer under the NuGet section. When you expand the Meta package, then you can find all the dependencies i.e. other packages. In the dependencies, once you scrolled down then you will find the Entity Framework Core NuGet packages already installed as shown in the below image.
Entity Framework Core Nuget Packages in ASP.NET Core Web Application

So the point that you need to remember is, when you create an ASP.Net Core web application using ASP.NET Core Version 2.1 or later, then by default you will have Entity Framework Core installed as part of the meta-package.

Multi-Layer Web Application:
When we want to develop a large application, we usually have at least the following 3 layers
  1. Presentation Layer
  2. Business Logic Layer
  3. Data Access Layer
These layers are implemented as separate projects. And the Entity Framework Core is usually required in the Data Access Layer project as this layer is going to interact with the database. The Data Access Layer project is usually a class library project and a class library project by default does not usually have the meta-package referenced. As it does not have the meta-package installed, so this means, the Entity Framework Core is not installed for the Data Access Layer project.

In order to install the Entity Framework Core to interact with the SQL server database, you need to install the following NuGet packages.
How to Install Entity Framework Core in Visual Studio

  1. Microsoft.EntityFrameworkCore.SqlServer has a dependency on Microsoft.EntityFrameworkCore.Relational package.
  2. Similarly, Microsoft.EntityFrameworkCore.Relational package has a dependency on Microsoft.EntityFrameworkCore package.
  3. Microsoft.EntityFrameworkCore package has a dependency on several other packages.

Entity Framework Core Packages Dependency

Note: When you install Microsoft.EntityFrameworkCore.SqlServer package, then it also automatically installs all the other dependency NuGet packages.

Installing Entity Framework Core in the Class Library Project:
Create a class library Project. Once you create the class library project expand the dependencies node as shown below.
Installing Entity Framework Core in the Class Library Project

As you can see in the above image, we don’t have the meta-package installed and hence we don’t have the entity framework core installed in our application.

In order to install entity framework core, Right-click on the “Dependencies“ node in Solution Explorer and then select “Manage NuGet Packages“ from the context menu as shown in the below image.
Installing Entity Framework Core

This will open the NuGet Package Manager interface. Click on the Browse tab and search for Microsoft.EntityFrameworkCore.SqlServer in the search box at the top left corner as shown in the below image. Based on the asp.net core version installed the entity framework core version compatibility with your .net core framework.
Installed Entity Framework Core

Note: We want to install Entity Framework Core to interact with the SQL Server database, so we installed the Microsoft.EntityFrameworkCore.SqlServer package. This package is usually called the Database provider package.

If you are using a different database other than SQL server, then you need to install that database provider-specific NuGet package. For example, if you want to use MySQL as your database, then install Pomelo.EntityFrameworkCore.MySql database provider package. Along the same lines, if you want to use PostgreSQL as your database, then use Npgsql.EntityFrameworkCore.PostgreSQL database provider package.

You can find all provider-specific NuGet packages on the following MSDN page.

https://docs.microsoft.com/en-us/ef/core/providers/

When you are installing the entity framework it will ask you to accept the license terms associated with the packages that are going to be installed as shown in the image below. Accept the license.
Accepting Terms in Entity Framework Core

Once the entity framework core installed, you will find the packages in the Meta package as shown in the below image.
Entity Framework Core Meta packages

Alternatively, you can also use the Package Manager Console to install the Entity Framework Core package. Go to Tools -> NuGet Package Manager -> Package Manager Console and execute the following command to install the SQL Server provider package.

PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer

In the next article, I am going to discuss the DbContext class in Entity Framework Core. Here, in this article, I try to explain how to install the entity framework core.

Summary:
I hope this post will be helpful to understand How to Install Entity Framework Core
Please share this post with your friends and colleagues.
For any queries please post a comment below.
Happy Coding 😉
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Post Older Post

0 comments:

Post a Comment

If you like this website, please share with your friends on Facebook, Twitter, LinkedIn.

Join us on Telegram

Loved Our Blog Posts? Subscribe To Get Updates Directly To Your Inbox

Like us on Facebook

Popular Posts

  • What is Dependency Injection(DI)
    Hi friends! Today we are going to learn about Dependency Injection and in our last session we have come across Static classes and where it s...
  • C# Programming Examples on Sorting
    Today i am going to tell you some of the Sorting programming questions in C#. Q1- Write a C# program to perform Selection sort. Ans:  Sel...
  • Calling Web API Service in a Cross-Domain Using jQuery AJAX
    In this article, I am going to discuss Calling Web API Service in a Cross-Domain Using jQuery AJAX . Please read our previous article befor...
  • ViewBag in ASP.NET Core MVC
    In this article, I am going to discuss the use of ViewBag in ASP.NET Core MVC application with examples. Please read our previous article ...
  • Recursion And Back Tracking
    In this article, I am going to discuss Recursion And BackTracking in detail. Please read our previous article where we discussed Master Th...
  • What is Abstract Class and When we should use Abstract Class
    Hi friends! In our previous sessions we have seen  Difference Between Class and Struct . And in our last session  we learnt Usability of Sec...
  • Binary to Decimal Conversion in C# with Examples
    In this article, I am going to discuss the Binary to Decimal Conversion in C# with some examples. Please read our previous article where w...

Blog Archive

Contact Form

Name

Email *

Message *

Tags

.Net .Net Core .Net Core MVC Algorithm Angular Anonymous Types Asp.Net Asp.Net MVC Blazor C# Data Structure Database Design Patterns Entity Framework Entity Framework Core Filters Interview Question Management Studio Programming Programs SQL Server SSMS Web API

Copyright © C# Techtics | All Right Reserved.

Protected by Copyscape