【问题标题】:Best way to structure my shopping database?构建我的购物数据库的最佳方式?
【发布时间】:2014-12-24 07:41:35
【问题描述】:

现在我的数据库具有以下(简化)格式:

ShoppingList
{
     List<ListProduct> listProducts
}

ListProduct
{
    int quantity
    Product product
}

Product

{
     information about the overall product...
     List<StoreProduct> StoreProduct

}

StoreProduct

{
     information about the specific product and the store
}

一般来说,shoppinglist 包含一个 listproducts 列表,每个列表都包含他们的数量和他们的 product,每个列表都包含 >商店产品

这一切都很好 - 但是,在我的购物清单中,我想跟踪购买了哪些商店产品。现在我不能只在我的 storeproducts 中添加一个“purchased”布尔值,因为它们用于多个购物清单(静态信息)。

我想添加 ListProduct 的 purchaseProduct 属性,该属性将设置为购买的 storeProduct,否则为 null。

但是我不确定是否存在更好的解决方案?我的架构已经很复杂,所以如果没有必要,我不想让它变得更复杂。

更新: 这是我的客户表:

Customer
{
    List<ShoppingList> shoppingLists
}

【问题讨论】:

    标签: database entity-framework database-design relational-database


    【解决方案1】:

    您为什么不创建一个新表,其中包含对 Customer 的 CustomerID 列引用和另一个列引用 StoreProduct。用它来存储所有购买的产品。对于此类问题,我建议您列出与 Customer 相关的 Schema。

    【讨论】:

    • 客户有一个 ShoppingLists 列表。假设您的建议是 ProductPurchase 将引用:1 StoreProduct, 1 ShoppingList - 这是正确的吗?但是我仍然需要跟踪 PurchasedProduct 的数量(其中 ListProduct 包含)
    • @JensOlsen112 然后是 ListProduct ID 的外键。每个购物清单都应该有一些正确的客户 ID。如果是这样,那么您可以直接引用它并进行加入
    猜你喜欢
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2010-11-27
    • 2023-03-16
    • 2020-01-21
    相关资源
    最近更新 更多