无需详细说明,现在我有两个实体:发票和产品。如果表中的记录总数没有减少,而是添加了一个新表(如果这个判断错误,正确我)
发票代码:
public class Invoice
{
[Key]
public long Id { get; set; }
///Any property
public virtual ICollection<Product> CurrentProducts { get; set; } = new HashSet<Product>();
///Any property
}
产品代码: 任何东西都可以是产品
public class Product
{
[Key]
public int Id { get; set; }
///Any property
public virtual ICollection<Invoice> Invoices { get; set; } = new HashSet<Invoice>();
///Any property
}
商品代码:
public class CatItem
{
[Key]
public int Id { get; set; }
///Any property
public short Quantity { get; set; }
public virtual int ProductId { get; set; }
public virtual Product Product { get; set; }
public virtual long InvoiceId { get; set; }
public virtual Invoice Invoice { get; set; }
///Any property
}
我明白通过 cartItem 做什么更正确,但是没有更好的实现购物车的做法吗?