2011-08-28 53 views
0

我有一個看起來像這樣的數據庫:建模1-n的問題

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

這裏我有ProductProductStore,也1-多StoreProductStore之間1-多。當我創建模型時,我基本上有類似

Product.ProductStores 

並且這會在編寫UI(例如數據綁定)時產生問題。當我使用模型時,查詢數據總是會返回ProductStores集合中只有一個ProductStore,因爲我總是一次與一個商店合作(PK:ProductID + StoreId)。我還需要爲商店共同使用產品表,因此需要ProductStoreTable

有沒有一種方法可以讓我代表產品 - > ProductStore模型1-> 0..1,這是actualy數據庫1->多少?

感謝, 戈蘭

+0

你使用什麼ORM? – Eranga

回答

0

我通常名爲ProductStore的產品,只是返回this.ProductStores.FirstOrDefault創建Porperty處理這()。並在集合上清除this.ProductStores並添加新的,如果它們不相同。

+0

謝謝,簡單而乾淨。 :) – Goran