How do I separate my concerns please so that I could have sub categories on each product categories. Example Car category will point to new cars and old cars. Below are my category class and product class code that generate my database. Thanks for your help.
Category class:
public class Category
{
[ScaffoldColumn(false)]
public int CategoryID { get; set; }
[Required, StringLength(100), Display(Name = "Name")]
public string CategoryName { get; set; }
[Display(Name = "Product Description")]
public string Description { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
Product Class:
public class Product
{
[ScaffoldColumn(false)]
public int ProductID { get; set; }
[Required, StringLength(100), Display(Name = "Name")]
public string ProductName { get; set; }
public string Description { get; set; }
public string ImagePath { get; set; }
[Display(Name = "Price")]
public double? UnitPrice { get; set; }
[Required, StringLength(100), Display(Name = "Seller")]
public string Seller { get; set; }
public DateTime Date { get; set; }
public int? CategoryID { get; set; }
public virtual Category Category { get; set; }
}
Context class:
public class ProductContext : DbContext
{
public ProductContext() : base("my")
{
}
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<CartItem> ShoppingCartItems { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }
public DbSet<State> States { get; set; }
}
Meanwhile I tried to follow this related topic in stockoverflow but It's a bit confusing. Thanks for taking your time to help me.