Installing Entity Framework Core
In this video we will see step by step installation of entity framework into application.
Depending on our requirement we set up the project. For example if your application is
Single Layer Web Application
If it’s a small project, you may have your presentation layer, business layer and data access layer all in one project. These means we can install the entity framework to our web application it self
Multi Layer Web Application
In a large application we will usually have at least the following 3 layers
- Presentation Layer
- Business Logic Layer
- Data Access Layer
These layers are implemented as separate projects. Entity Framework Core is usually required in the Data Access Layer project. The Data Access Layer project is a class library project and does not usually have the meta package referenced.
Packages Required
- Microsoft.EntityFrameworkCore.SqlServer: This nuget package contains SQL Server specific functionality
- Microsoft.EntityFrameworkCore.Relational: This nuget package contains functionality that is common to all relational databases
- Microsoft.EntityFrameworkCore: This NuGet package contains common entity framework core functionality.
Create .net core class library project and install the above Nuget packages.
Right click on the “Dependencies” node in “Solution Explorer” and Select “Manage NuGet Packages” from the context menu and in the search box just type ‘Microsoft.EntityFrameworkCore’ and as we discuss we need to three packages
We want to use SQL Server as the database for our application, so we used the nuget package Microsoft.EntityFrameworkCore.SqlServer. This package is usually called Database provider package.
If you want to use a different database with your application, then you will have to install that database provider specific nuget package instead of Microsoft.EntityFrameworkCore.SqlServer database provider 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, use Npgsql.EntityFrameworkCore.PostgreSQL database provider package.
In the next tutorial will see code first approach to create database from the model class.
You can watch our video version of this tutorial with step by step explanation.