Entity Framework

Entity Framework is an open source ORM (Object Relational Mapping) that can understand your domain model and automatically generate most of the code (SQL) you would otherwise have to write in your data access layer (DAL). Microsoft's implementation of the Entity Framework works well with various databases: SQL Server, MySql, Oracle, PostgreSQL, SQLite and many others.

Data Access Layer (DAL)

In software that uses databases, a data access layer (DAL) is typically created. In the data acecss layer, you write the code that communicates with the database. These could often be SQL commands that implement the 4 CRUD operations: create, read, update and delete. These 4 operations are then implemented for each entity you have in your domain model.

That's fine, but something always comes up that causes the domain model to change. Maybe you just need to add some information to an entity. Maybe there needs to be a new relationship between 2 entities. And when that happens, updating the DAL is a big task that can take a lot of time. It's a great source for making mistakes.

Entity Framework is an Object Relational Mapping (ORM)

To overcome the challenges of a DAL that takes a lot of time to maintain, some good software people have come up with an object relational mapper (ORM). The idea of an ORM is that it can automatically generate the code in the DAL. This avoids spending a lot of time updating it and eliminates some sources of errors.

There are many different ORMs for different programming languages. Take a look at this list of ORM software.


Entity Framework (EF)

The Entitty framework is Microsoft's implementation of an ORM that can be used in their .NET development tools. It is implemented in a very nice way. You create the entities from your domain model such as C# classes and tell the entity framework how to communicate with the database you have chosen. Then EF can automatically create the database and all the necessary tables. Subsequently, it can also update the database and DAL when you need to make changes to the domain model. You will also automatically get access to methods that implement the 4 CRUD operations without having to write SQL code or anything else.

Read more about the entity framework here: Entity Framework Core

EF also supports many different databases. This means, for example, that it is quite easy to change the underlying database, something that could otherwise be quite a daunting task due to variations in the SQL deals.

Here is a list of possible database providers in EF: Database Providers


I have used the entity framework in all the .NET projects I have worked on over the last few years. Most recently, I've used it in my online booking system. EF is particularly strong when you also use clean architecture, the two tools work really well together.