diff --git a/Chapter10/WorkingWithEFCore/WorkingWithEFCore/Category.cs b/Chapter10/WorkingWithEFCore/WorkingWithEFCore/Category.cs new file mode 100644 index 0000000..af88b20 --- /dev/null +++ b/Chapter10/WorkingWithEFCore/WorkingWithEFCore/Category.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations.Schema; // [Column] + +namespace Packt.Shared; +public class Category +{ + // these properties map to columns in the database + public int CategoryId { get; set; } + public string? CategoryName { get; set; } + [Column(TypeName = "ntext")] + public string? Description { get; set; } + // defines a navigation property for related rows (one to many relationship with Products) + public virtual ICollection Products { get; set; } + + public Category() + { + // to enable developers to add products to a Category we must + // initialize the navigation property to an empty collection + Products = new HashSet(); + } +} diff --git a/Chapter10/WorkingWithEFCore/WorkingWithEFCore/Product.cs b/Chapter10/WorkingWithEFCore/WorkingWithEFCore/Product.cs new file mode 100644 index 0000000..2a1f860 --- /dev/null +++ b/Chapter10/WorkingWithEFCore/WorkingWithEFCore/Product.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Packt.Shared; + +public class Product +{ + public int ProductId { get; set; } + [Required] [StringLength(40)] public string ProductName { get; set; } = null!; + [Column("UnitPrice", TypeName = "money")] + public decimal? Cost { get; set; } + [Column("UnitsInStock")] + public short? Stock { get; set; } + public bool Discontinued { get; set; } + // these two define the foreign key relationship + // to the Categories table + public int CategoryId { get; set; } + public virtual Category Category { get; set; } = null; +} \ No newline at end of file