5 CRUD operations

 

This chapter covers

  • Performing SELECT, INSERT, UPDATE, and DELETE queries with Entity Framework Core
  • Handling different requests using HTTP GET, POST, PUT and DELETE methods
  • Introducing Data validation concepts
  • Implementing some Server-Side Validation techniques

In the previous chapter we have dedicated ourselves to the installation, set up and configuration of all the prerequisites necessary to interact with a DBMS, as well as learning 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 are ready to perform the typical data-related tasks: Create, Read, Update, and Delete (CRUD), which will be respectively handled by INSERT, SELECT, UPDATE and DELETE SQL queries. Being able to perform these operations using Entity Framework Core is a great way to allow the MyBGList Web API application we're working with to interact with the DBMS we've set up in the previous chapter using a uniform, well-structured, and convenient approach.

In this chapter we'll perform several read and write operations required by our concrete scenario against our Data Model using the EF Core's ApplicationDbContext class: these tasks will greatly help us to develop the required skills to interact with our database for 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 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

5.3.4 Adding the SeedController

5.3.5 Reading the CSV file

5.3.6 Executing the SeedController

5.4 Reading Data

5.4.1 Paging

5.4.2 Sorting

5.4.3 Filtering

5.5 Updating and Deleting Data

5.5.1 Updating a BoardGame

5.5.2 Deleting a BoardGame

5.6 Exercises