我正在尝试分组,然后旋转一些数据以显示在asp.net视图上。
这是我的View Model类。
public class myModel
{
public string id { get; set; }
public string fund{ get; set; }
public string account{ get; set; }
public string amount{ get; set; }
}
以下是从数据库返回的示例数据
id fund account amt
1 101 1001 25.70
2 101 1001 10.00
3 101 1001 12.00
4 101 1002 -5.0
5 201 2001 12.00
6 201 2001 11.00
现在我有一个查询返回上面的数据,并将其映射到上面提到的模型。从本质上讲,我有一个包含上述数据的对象列表。
现在,我想对这些数据进行分组和求和,并在我的视图中显示如下所示。
fund
account sum of all amt
account sum of all amt
fund
account sum of all amt
account sum of all amt
所以就像这样
101
1001 47.00
1002 -5
....
201
2001 23
and so on
我该怎么做呢?
我有一个上面提到的对象列表。
我正在考虑创建另一个类,并将其映射到它,但我可能会让它变得比需要的更复杂
public class pivot
{
public string fund { get; set; }
public List < pivotdetail >detail{ get; set; }
}
public class pivotdetail
{
pretty obvious
}
我该怎么做或者应该怎么做,有什么想法吗?
https://stackoverflow.com/questions/56468188
复制相似问题