I am searching for an extension to the solution given in this stackoverflow question. Using Linq to group a list of objects into a new grouped list of list of objects
If I wanted to devide a bunch of PersonData into a List. How should I proceed if I only want to keep the emp string inside the label of ListData and not in the Point Class.
return db.persondatas.Where.GroupBy(i => new { i.name, i.y })
.Select(i => new Point
{
x = i.x
emp = i.name
y = i.Sum(s => s.y)
})
.GroupBy(i => i.emp)
.Select(i => new ListData
{
label= i.Key,
data= i.ToList()
}).ToList();
public Class Point
{
double x;
double y;
}
public Class ListData
{
List<Point> data;
string label;
}
public Class PersonData
{
string name;
int x;
int y;
}