I'm trying to group and then pivot some data to display on asp.net view.
Here is my View Model class.
public class myModel
{
public string id { get; set; }
public string fund{ get; set; }
public string account{ get; set; }
public string amount{ get; set; }
}
Here is a sample data returned from database
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
Now I have a query that returns above data and maps it to the model mentioned above. Essentially I have a list of objects with above mentioned data.
Now I want to group and sum this data and display like below in my view.
fund
account sum of all amt
account sum of all amt
fund
account sum of all amt
account sum of all amt
so something like
101
1001 47.00
1002 -5
....
201
2001 23
and so on
How do I go about doing this?
I have a list of objects as mentioned above.
I'm thinking of creating another class and them mapping to it but I'm perhaps making it more complicated than it needs to be
public class pivot
{
public string fund { get; set; }
public List < pivotdetail >detail{ get; set; }
}
public class pivotdetail
{
pretty obvious
}
Any ideas on how I can do this or I should approach this?