Building EF Core Models for the Northwind Tables
Explore how to build and configure EF Core entity models representing Northwind database tables. Understand defining entity properties, primary keys, relationships, and using Fluent API for database mappings.
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:
Step 3: In Product.cs, define a class named Product, as shown in the following code:
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 ...