このstackoverflowの質問に記載されているソリューションの拡張機能を探しています。 Using Linq to group a list of objects into a new grouped list of list of objectsLINQグループのデータをリストを含むオブジェクトのリストに追加する+特定の元のデータを選択する
リストにPersonDataをまとめたいとしたら、 emp文字列をPointクラスのラベルではなくListDataのラベルの中に保持したい場合は、どのように進めるべきですか。ここで
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;
}
あなたのコードに問題は何? –
あなたはまだグループ化のために 'x'と' y'を保つ必要がありますか?同じグループに同じ名前の全員をグループ化したいだけですか? – Xiaoy312
誰もが同じ名前を持つグループに属していれば、Persondata xとyからのポイントデータを持つListを持ちます。 – Hinnom