Good day. Began to study the Entity Framework. and I write on ASP.net mvc5 an example of an online store. Faced the problem of building a domain model (more precisely, connections between entities). There is an essence Product (Product) and order (Order). It would be easy to establish a many-to-many connection between them. But to avoid duplication of products in the order you need to enter more Quantity (LineProduct). LineProduct is a product and how much it is ordered (for example: Bread - 2, Milk - 10, ...). I have sketched a model, but it seems to me difficult, because I think a typical task is a typical solution. I don't really need the Lines table. I fill in the Products table, the buyer forms Orders. You must be able to select all the products of a single order and which orders include the selected product. Thank you in advance for your participation !!!!!
Products
public class Product { [Key] public int Id { get; set; } [Required(ErrorMessage = "Введите название продукта")] public string Name { get; set; } [Required(ErrorMessage = "Введите цену продукта")] public decimal UnitPrice { get; set; } public string PictureRef { get; set; } public List<Line> Lines { get; set; } = new List<Line>(); } Lines
public class Line { [Key] public int Id { get; set; } [Required] public int Quantity { get; set; } [Required] public Product Product { get; set; } } Orders
public class Order { [Key] public int Id { get; set; } [Required] public Address DeliveryAddress { get; set; } [Required] public virtual List<Line> Lines { get; set; } = new List<Line>(); }