Reading stock levels

Let's look at how we might persist this to a SQL Server database using Entity Framework Core:

  1. Because we're persisting all this to a database, we'll install Entity Framework Core in our API:
Install-Package Microsoft.EntityFrameworkCore.SqlServerInstall-Package Microsoft.EntityFrameworkCore.Tools

This installs both the Entity Framework libraries and tools that are required.

  1. The next step is to create our model; that is, create a map of the database in a C# class. Your model could look something like this:
public class Product{    public int Id { get; set; }    public string Description { get; set; }    public int StockCount { get; set; }}

It should sit somewhere visible to your application. I've added mine to a subfolder ...

Get C# 8 and .NET Core 3 Projects Using Azure - Second 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.