6 Tips and techniques for reading and writing with EF Core

 

This chapter covers

  • Selecting the right approach to read data from the database
  • Writing queries that perform well on the database side
  • Avoiding problems when you use Query Filters and special LINQ commands
  • Using AutoMapper to write Select queries more quickly
  • Writing code to quickly copy and delete entities in the database

The first four chapters cover different ways to read/write to a database, and in chapter 5, you used that information to build the Book App—an ASP.NET Core web application. This chapter brings together lots of different tips and techniques for reading and writing data with EF Core.

The chapter is split into two sections: reading from the database and writing to the database. Each section covers certain read/write issues you may come across, but at the same time explains how EF Core achieves the solutions. The aim is to give you lots of practical tips by solving different problems and, at the same time, deepen your knowledge of how EF Core works. The tips are useful, but in the long run, becoming an expert on EF Core is going to make you a better developer.

TIP

Don’t forget that the companion Git repo (http://mng.bz/XdlG) contains unit tests for every chapter of the book. For this chapter, look in the Test project in the master branch for classes starting with Ch06_. Sometimes, seeing the code is quicker than reading the words.

6.1 Reading from the database

6.1.1 Exploring the relational fixup stage in a query

6.1.2 Understanding what AsNoTracking and its variant do

6.1.3 Reading in hierarchical data efficiently

6.1.4 Understanding how the Include method works

6.1.5 Making loading navigational collections fail-safe

6.1.6 Using Global Query Filters in real-world situations

6.1.7 Considering LINQ commands that need special attention

6.1.8 Using AutoMapper to automate building Select queries

Summary