12 Saving data with Entity Framework Core

 

This chapter covers

  • Understanding what Entity Framework Core is and why you should use it
  • Adding Entity Framework Core to an ASP.NET Core application
  • Building a data model and using it to create a database
  • Querying, creating, and updating data with Entity Framework Core

Most applications that you’ll build with ASP.NET Core require storing and loading some kind of data. Even the examples so far in this book have assumed that you have some sort of data store—storing exchange rates, user shopping carts, or the locations of physical stores. I’ve glossed over this topic for the most part, but typically you’ll store this data in a database.

Working with databases can be a rather cumbersome process. You have to manage connections to the database, translate data from your application to a format the database can understand, and handle a plethora of other subtle problems. You can manage this complexity in a variety of ways, but I’m going to focus on using a library built for modern .NET: Entity Framework Core (EF Core). EF Core is a library that lets you quickly and easily build database access code for your ASP.NET Core applications. It’s modeled on the popular Entity Framework 6.x library, but it has significant changes that make it stand alone in its own right as more than an upgrade.

12.1 Introducing Entity Framework Core

12.1.1 What is EF Core?

12.1.2 Why use an object-relational mapper?

12.1.3 When should you choose EF Core?

12.1.4 Mapping a database to your application code

12.2 Adding EF Core to an application

12.2.1 Choosing a database provider and installing EF Core

12.2.2 Building a data model

12.2.3 Registering a data context

12.3 Managing changes with migrations

12.3.1 Creating your first migration

12.3.2 Adding a second migration

12.4 Querying data from and saving data to the database

12.4.1 Creating a record

12.4.2 Loading a list of records

12.4.3 Loading a single record

12.4.4 Updating a model with changes

12.5 Using EF Core in production applications

12.6 Summary

sitemap