C# GroupBy的使用

var skill = query.GroupBy(i=>i.SkillTypeId)
.Select(i => new
            {
              skillType=i.key,
              skill=i.Select(s=>new{
              i.Id,
              i.Level,
              i.IsEquiped,
            })                          
 

输出结果

{
"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,
                  
                },
     ]
}

转自:https://blog.csdn.net/hhhhhhenrik/article/details/81980594?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

猜你喜欢

转载自www.cnblogs.com/firstcsharp/p/12384941.html