5 CRUD operations

 

This chapter covers

  • Performing SELECT, INSERT, UPDATE, and DELETE queries with EF Core
  • Handling requests using the HTTP GET, POST, PUT, and DELETE methods
  • Implementing paging, sorting, and filtering using EF Core
  • Using data-transfer objects (DTOs) to exchange JavaScript Object Notation (JSON) data with the client

In chapter 4, we dedicated ourselves to the installation, setup, and configuration of all the prerequisites for interacting with a database management system (DBMS), and we learned the means, techniques, and reasons to do that. Now that we have a database context and an object-relational mapper (ORM) up and running, we’re ready to perform the typical data-related tasks: create, read, update, and delete (CRUD) operations, which are handled by Insert, Select, Update, and Delete SQL queries, respectively. Performing these operations with Entity Framework Core (EF Core) allows our MyBGList web API application to interact with the DBMS we set up in chapter 4.

In this chapter, we’ll take advantage of our data model to perform several read and write operations required by our concrete scenario, using the EF Core’s ApplicationDbContext class. These tasks will help us develop the skills required to interact with our database throughout the rest of the book.

5.1 Introducing LINQ

5.1.1 Query syntax vs. method syntax

5.1.2 Lambda expressions

5.1.3 The IQueryable<T> interface

5.2 Injecting the DbContext

5.2.1 The sync and async methods

5.2.2 Testing the ApplicationDbContext

5.3 Seeding the database

5.3.1 Setting up the CSV file

5.3.2 Installing the CsvHelper package

5.3.3 Creating the BggRecord class