What is Entity Framework in 2020

This article gives the introduction about Entity Framework and its application over .Net framework. Entity framework is an open-source ORM framework for .NET applications. Previously developers use ADO.Net for connecting to Database.But currently Developers are using EntityFramework for connecting to database using .net objects. Developers no need to write large queries for accessing database records. Entity framework is a mediator between business entities(Model layer) and database. Its work is to get data from database and converts it to business entities objects and also updates data from business entities to database.

In our legacy applications, we use ADO.NET to retrieve and save application data to database.In ADO.NET, we will open a connection to the database,create a dataset to store data from the database. To overcome this process,Microsoft provided a framework called 'Entity Framework' which automate all these database related activities of your application. Entity Framework is an open source ORM framework for .NET applications supported by Microsoft.

In otherwords, as per official definition: "Entity Framework is an object-relational mapper(ORM) that enables .Net developers to work with a database using .NET objects.It eliminates the need for data-access code that developers need to write."
Entity Framework Latest versions: There are 2 latest versions in entity framework 1)EF6 and 2)EF Core.

Entity Framework Approaches:

There are three kinds of entity framework approaches.

  • CODE FIRST
  • MODEL FIRST
  • DATABASE FIRST

CODE FIRST:

Here domain classes will be created first and using that classes the database will be created. For eg:-

public Class Customer 
{ 
public int Customerid{get;set;}
public string CustomerName{get;set;}
public string Address{get;set;}
public string City{get;set;}
public string Country{get;set;}
}
                        

Note: So the above domain class will get converted to table during database creation.

MODEL FIRST:

In Model first approach, you create entities,relationships, inheritance hierarchies on EDMX file of the Visual designer which is integrated to Visual Studio and then generate database from your model.

DATABASE FIRST:

In database first approach, you develop the context and entities from the existing database using EDM Wizard in our Visual Studio environment.

EF 6 EF Core
It was released in 2008 with .Net Framework 3.5 It was released in June 2016 with .Net Core 1.0
Windows only Windows , Linux, osx
Works on .Net framework 3.5+ Works on .Net framework 4.5+ and .Net core