1

假設我有這3類下面:聚合根域邏輯

public class User 
{ 
    public int UserId { get; set; } 
    public ICollection<Location> { get; set; } 
} 
public class Location 
{ 
    public int LocationId { get; set; } 
    public int UserId { get; set; } 
    public ICollection<Sale> Sales { get; set; } 
} 
public class Sale 
{ 
    public int SaleId { get; set; } 
    public int LocationId { get; set; } 
    public decimal Cash { get; set; } 
} 

我有一個頁面,我會顯示總現金對誰在登錄的用戶的所有位置上的要求我想到我將GetTotalCash()方法放在Locations類中,並通過LINQ實現總結,但問題是我將通過User類訪問Locations對象,我將無法調用由於Location屬性是User類上的ICollection,因此使用summation方法。我應該把邏輯放在用戶類上嗎?但是這並不合理,因爲它不是用戶對象的行爲,或者它不是?

順便說一句,我使用的是EF 4.1代碼第一次和MVC 3

感謝一大堆!

回答

0

實現位置類GetTotalCash()方法,並在用戶類實現GetCashForLocation()以獲得現金選擇的位置(這將委託調用位置類GetTotalCash(),並在用戶類將遍歷實現GetTotalCash()他們的所有位置,並求和的現金。

那麼reprehensibilites的每個信息專家級分配,並從聚合根委派

+0

「那麼reprehensibilites的每個信息專家級分配,並從聚合根授權」。什麼你是這個意思嗎? – gnaungayan

+0

Als o,它似乎GetCashForLocation應該屬於一個存儲庫? – gnaungayan

+0

信息專家是GRASP模式之一http://en.wikipedia.org/wiki/GRASP_(object-oriented_design) 這些模式描述您應該在哪裏設計方法以及如何分配職責。 –