1

假设我有以下课程。

public class Location
{
    public Id { get; set;}
    public Name { get; set;}
}

我有一个名为 Location 的网页,看起来像这样。

txtId  
txtName 

txtCountStaffWorkersAtLocation 
txtCountVehiclesAtLocation
txtCountNonStaffWorkersAtLocation 
txtCountetc

listViewPersonnel
listViewVehicles

现在我正在调用存储库以在视图上显示 Location 字段,但我对获取和显示其他字段数据的正确方法感到困惑。它们显然与位置类关系不大。当我从数据库设置位置类时,我是否将计数放在位置类中并填写它们?我在某个地方有一个结构对象,它只有这些计数字段吗?你们通常如何处理与域对象关系不大的页面上显示的对象?

谢谢

4

1 回答 1

0

我建议将 StaffPersonnel、NonStaffPersonnel 和 Vehicles 实现为 Location 对象的属性,其中每个属性都返回关联对象的集合。然后对于计数,您可以从位置对象中获取如下属性:

loc.Vehicles.Count
loc.StaffPersonnel.Count
loc.NonStaffPersonnel.Count
于 2009-04-07T16:57:22.000 回答