Writing the Product class
In this section, we will update our Product
class. It is a simple object that is used for data manipulation benchmarks and contains properties that match the Products
table in the Northwind
database. Follow these steps:
- Open the
Product
class and update it as follows:using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; [Table("Products")] public class Product { }
Here, we annotated our class with the Table
annotation, passing the name of the table in the Northwind
database that this class maps to into the annotation.
- Add the following properties and annotations:
[Key] public int ProductID { get; set; } public string ProductName { get; set; } [ForeignKey("Suppliers")] public int SupplierID { get; set; } [ForeignKey("Categories")] public int CategoryID { get; set; } public string QuantityPerUnit { get; set; } = "1" public decimal UnitPrice...