Lesson Sunday

So far, we've managed all SQL statements ourselves. We've written code both to issue SQL commands to the database and to process query results with libraries like MySQLDataReader.

Now we're going to begin exploring more advanced options. We'll use an object relational mapping (or ORM) framework to help simplify and manage our database interactions. In this lesson, we'll briefly discuss what an ORM does and why it's beneficial. Then we'll introduce the specific ORM our .NET 5.0 applications will use: Entity Framework Core.

Object Relational Mapping (ORM)


Object-Relational Mapping (ORM) allows us to query and manipulate database data in an object-oriented fashion. Essentially, ORMs turn database info into objects of the language we're working in. This way we can focus on writing in C# instead of needing to deal with raw SQL.

Object Relational Mapping is a language-agnostic concept. Different languages have different ORM libraries. For instance, Ruby uses a tool called Active Record, Python's commonly-used Django framework includes ORM, and Java has multiple open-source options available.

Entity Framework


Entity Framework (also called Entity) is a powerful library that simplifies the process of mapping objects to database records. We can use Entity to vastly simplify our database CRUD functionality.

Versions and Types

Entity Framework comes in two forms: Entity Framework and Entity Framework Core. To distinguish between the two, .NET developers refer to these types of Entity as EF6 (the latest version at the time of this writing) and EF Core.

  • EF6 was built to work with the .NET Framework and is not compatible with applications built using .NET Core.

  • EF Core has fewer features than EF6. However, it is lightweight and recommended for applications that don't require highly complex data manipulation.

Because we use .NET 5.0, we must also use Entity Framework Core.

Next Steps


In the next few lessons we'll walk through configuring Entity Framework Core to work with our own applications. Then we'll use Entity to help us write CRUD functionality that allows us to interact with our database without manually-constructed MySQL commands.

Lesson 21 of 36
Last updated more than 3 months ago.