...

/

Building EF Core Models for the Northwind Tables

Building EF Core Models for the Northwind Tables

Learn about creating entity classes for tables, establishing relationships between the entities, and configuring the context class.

Creating entity classes for Northwind databases tables

Let’s build models to represent two of the tables in the Northwind database. The two entity classes will refer to each other, so to avoid compiler errors, we will create the classes without any members first:

Step 1: In the WorkingWithEFCore project, add two class files named Category.cs and Product.cs.

Step 2: In Category.cs, define a class named Category, as shown in the following code:

Press + to interact
namespace Packt.Shared;
public class Category
{
}

Step 3: In Product.cs, define a class named Product, as shown in the following code:

Press + to interact
namespace Packt.Shared;
public class Product
{
}

Defining the Category and Product entity classes

The Category class, also known as an entity model, will be used to represent a row in the Categories ...