linq + groupby - add fields in select query

前端 未结 1 592
一生所求
一生所求 2021-01-24 13:42

question : can we made groupby to multiple fields in LINQ Currently - i have linq something like this

q = q.GroupBy(c => c.Id)
     .Select(g => new View         


        
相关标签:
1条回答
  • 2021-01-24 14:37

    Try this:

    q = q.GroupBy(c => new { c.Id, c.name,c.age,c.dob })
        .Select(g => new
        {
            Id = g.Key.Id,
            ENAME= string.Join(",", g.Select(x => x.CaseApprover).ToList()),
            Name = g.Key.name,
            Age = g.Key.age,
            Dob = g.Key.dob,
        });
    

    This will return an anonymous type, if you want these fields in your View class, just add them.

    0 讨论(0)
提交回复
热议问题