Linq學習筆記(二)——GroupBy 分組輸出資料
阿新 • • 發佈:2019-01-24
var skill = query.GroupBy(i=>i.SkillTypeId)
.Select(i => new
{
skillType=i.key,
skill=i.Select(s=>new{
i.Id,
i.Level,
i.IsEquiped,
})
}).ToList()
輸出結果
{ "skillType":“刀” "skill": [ { "Id": 35, "Level": 1, "IsEquiped": true, }, { "Id": 36, "Level": 1, "IsEquiped": true, }, ] "skillType":"劍" "skill": [ { "Id": 35, "Level": 1, "IsEquiped": true, }, { "Id": 36, "Level": 1, "IsEquiped": true, }, ] }