如何最好地实施购物车?

问题描述 投票:0回答:0

无需详细说明,现在我有两个实体:发票和产品。如果表中的记录总数没有减少,而是添加了一个新表(如果这个判断错误,正确我)

发票代码:

    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 示例的数据库: (https://i.stack.imgur.com/Y6wyC.png)

没有 CartItem 的数据库示例: https://i.stack.imgur.com/uEKyF.png)

我明白通过 cartItem 做什么更正确,但是没有更好的实现购物车的做法吗?

c# asp.net-web-api shopping-cart
© www.soinside.com 2019 - 2024. All rights reserved.