我有一个如下所示的数据库:
Product: PK(ProductId), ProductName.......
Store: PK(StoreId), StoreName......
ProductStore: PK(ProductId, StoreId), Price, Quantity
此处我在Product
和ProductStore
之间有1-many,在Store
和ProductStore
之间也有1-many。当我创建模型时,我基本上有类似
Product.ProductStores
这会在编写UI时产生问题(例如,数据绑定)。当我使用模型时,查询数据将始终只返回ProductStore
集合中的一个ProductStores
,因为我一直在使用一个商店(PK:ProductID + StoreId)。我还需要为商店提供公共产品表,因此需要ProductStoreTable
。
我有没有办法在模型1-> 0..1中代表Product-> ProductStore,这在数据库1->很多?
谢谢, 戈兰
答案 0 :(得分:0)
我通常通过在名为ProductStore的Product上创建一个只返回this.ProductStores.FirstOrDefault()的Porperty来解决这个问题。并在集合清除this.ProductStores并添加新的,如果它们不相同。