17 Working with data

 

This chapter covers

  • Caching data values or complete responses using ASP.NET Core
  • Working with Entity Framework Core to access data in a relational database

All the examples in the earlier chapters in this part of the book have generated fresh responses for each request, which is easy to do when dealing with simple strings or small fragments of HTML. Most real projects deal with data that is expensive to produce and needs to be used as efficiently as possible. In this chapter, I describe the features that ASP.NET Core provides for caching data and caching entire responses. I also show you how to create and configure the services required to access data in a database using Entity Framework Core. Table 17.1 puts the ASP.NET Core features for working with data in context.

Note

The examples in this chapter rely on the SQL Server LocalDB feature that was installed in chapter 2. You will encounter errors if you have not installed LocalDB and the required updates.

17.1 Preparing for this chapter

17.2 Caching data

17.2.1 Caching data values

17.2.2 Using a shared and persistent data cache

17.3 Caching responses

17.4 Caching output

17.4.1 Defining a custom cache policy

17.5 Using Entity Framework Core

17.5.1 Installing Entity Framework Core

17.5.2 Creating the data model

17.5.3 Configuring the database service

17.5.4 Creating and applying the database migration

17.5.5 Seeding the database

17.5.6 Using data in an endpoint

Summary