Chapter 5. Working with relational databases

 

This chapter covers

  • Accessing databases with .NET Standard System.Data classes
  • Using the SQLite in-memory database
  • Transforming data between objects and tables
  • Unit testing data-access code

Widget Corporation needs to keep better track of their supply chain, so they hire you to transform their paper-based process into software. You find that each part used in the manufacturing process comes from a different supplier, and that Widget Corp. is having trouble ordering the right supplies at the right time.

To solve this problem, you decide to use a relational database. The database will persist data, making it resilient to shutdown or power failure. It will enforce relationships between data, so that no one can add an order without indicating the supplier or part. It also makes the data queryable, which allows anyone to determine what parts are running out and need to be ordered soon. The employees of Widget Corp. shouldn’t have to learn the SQL commands to enter the data into the database manually. You’ll need to create software that makes it easy for them.

Now you get to apply your .NET Core skills. .NET Core is a great choice for database applications because of the powerful built-in data-access classes. In this chapter, you’ll explore the low-level data-access capability that’s built into the .NET Standard—encapsulated in the System.Data namespace. But before you start, you need a database.

5.1. Using SQLite for prototyping

5.2. Planning the application and database schema

5.3. Creating a data-access library

5.4. Ordering new parts from suppliers

Additional resources

Summary