【发布时间】:2011-10-31 15:31:52
【问题描述】:
假设我在下面有这 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。我应该把逻辑放在 User 类上吗?但这没有意义,因为它不是 User 对象的行为,还是这样?
顺便说一句,我使用的是 EF 4.1 Code First 和 MVC 3。
非常感谢!
【问题讨论】:
标签: c# asp.net-mvc-3 entity-framework-4.1 domain-driven-design