Creating data repositories for entities

Defining and implementing a data repository to provide CRUD operations is good practice:

  • C for Create
  • R for Retrieve (or Read)
  • U for Update
  • D for Delete

We will create a data repository for the Customers table in Northwind. We will follow modern good practice and make the repository API asynchronous.

In the NorthwindService project, create a Repositories folder.

Add two class files to the Repositories folder named ICustomerRepository.cs and CustomerRepository.cs.

ICustomerRepository should look like this:

using Packt.CS7;using System.Collections.Generic;using System.Threading.Tasks;namespace NorthwindService.Repositories{   public interface ICustomerRepository   { Task<Customer> CreateAsync(Customer c); ...

Get C# 7.1 and .NET Core 2.0 – Modern Cross-Platform Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.