【问题标题】:Modeling 1-n problem建模 1-n 问题
【发布时间】:2011-11-05 09:35:45
【问题描述】:

我有一个如下所示的数据库:

Product: PK(ProductId), ProductName.......
Store: PK(StoreId), StoreName......
ProductStore: PK(ProductId, StoreId), Price, Quantity

这里我有ProductProductStore 之间的1-many,以及StoreProductStore 之间的1-many。当我创建模型时,我基本上有类似的东西

Product.ProductStores

这在编写 UI 时会产生问题(例如数据绑定)。当我使用模型时,查询数据将始终在ProductStores 集合中只返回一个ProductStore,因为我总是一次使用一个商店(PK:ProductID+StoreId)。我还需要为商店提供通用产品表,因此ProductStoreTable 的必要性。

有没有办法可以在模型 1->0..1 中表示 Product->ProductStore,实际上是在数据库 1->many 中?

谢谢, 戈兰

【问题讨论】:

    标签: .net oop c#-4.0 model


    【解决方案1】:

    我通常通过在 Product 上创建一个名为 ProductStore 的 Porperty 来处理这个问题,它只返回 this.ProductStores.FirstOrDefault()。并在片场清除 this.ProductStores 并添加新的,如果它们不同的话。

    【讨论】:

      猜你喜欢
      • 2010-12-03
      • 2011-09-24
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      • 2014-05-28
      相关资源
      最近更新 更多