Linq distinct - Count

前端 未结 5 605
一向
一向 2020-11-29 01:16

I am looking to perform a query on an example list of objects

Date     Username

01/01/2011 james
01/01/2011 jamie
01/01/2011 alex
01/01/2011 james
02/01/201         


        
5条回答
  •  余生分开走
    2020-11-29 01:53

    Another way to solve this is to group twice, check the sample

              var dist = listLogins.GroupBy(d => d.date + d.Username)
                  .Select(x => x.First())
                  .GroupBy(d => d.date).Select(y => new { date = y.Key, count = y.Count() }).ToList();
    

提交回复
热议问题