Introduction to Entity Framework Core

 In this article, we will learn Entity Framework Core (EF Core) however before EF Core, we will learn Object-Relational Mappers (ORM).

Object-Relational Mappers (ORM):

Object-Relational Mappers act as a connector between object-oriented programming languages and relational databases. They eliminate the need to write SQL queries, instead providing an object-oriented layer that standardizes interfaces, reduces boilerplate code, and accelerates development time. Object-oriented programming can be complex, but ORMs simplify the process by creating a structured map of how objects are related to different tables in the database. This map helps developers to understand the underlying structure, and allows ORMs to convert data between tables and generate SQL code for the relational database to manage insertions, updates, selections, and deletions in response to changes made by the application. 

Entity Framework Core is an ORM framework provided by Microsoft and in the next section, we will understand EF Core.

Entity Framework Core

EF Core is an ORM framework designed for data access in .NET. EF Core was released concurrently with .NET Core and its main purpose is to simplify data access for .NET applications. By utilizing an object-relational mapping approach, EF Core provides a standardized and efficient way to communicate between object-oriented programming languages and relational databases, making it easier to develop and maintain .NET applications.

There are two different approaches to implement EF Core

  • Database First Approach
  • Code First Approach

Lets briefly understand each of these approaches.

Database First Approach

In the database first approach, we design our database first by create tables and defining relations in our database and against these tables, entity framework core generates code (required classes) in our project. This approach works well where we have legacy applications and databases are already created.

Code First Approach

In the code first approach, we start with the code and create classes. And entity framework code generates database tables against these classes. The user does not need to worry about tables and their relations. EF core handles it out of the box. This approach works well when the user is starting a new project or needs to learn the relational database better.

There could be third approach by combining both of above that is to start with the database first and then convert it into the code first approach, This approach is suitable where we create the initial database and then use the database first approach to generate the code classes. Once initial code and database is ready then from onwards use the code first approach to manage the updates in database. We will look into details in upcoming sections.


You can learn more about entity framework from the following link: https://shujarehman.org/wp/category/entity-framework-core/




Comments