根据重复汇总日期

时间:2019-10-29 12:34:19

标签: asp.net asp.net-mvc entity-framework asp.net-core entity-framework-6

所以我想展示一个饼图,并在  每天,为此,我想总结过去7天的每一天。 这就是我试图做的:

IEnumerable<DateTime> commentList;
        commentList = await _context.Commentdb.Select(a => a.dateSubmit)
            .GroupBy(b => b.Day).ToListAsync();

但它不起作用,而是显示此错误:

 Cannot implicity convert type List<int,DateTime> to List<DateTime>

1 个答案:

答案 0 :(得分:0)

您需要先按日期和日期进行分组。

IEnumerable<DateTime> commentList;
    commentList = await _context.Commentdb.GroupBy(b => new { b.Day, b.dateSubmit }).Select(a => a.Key.dateSubmit)
        .ToListAsync();

更新:

 IEnumerable<DateTime> commentList;
    commentList = await _context.Commentdb.Where(x => x.dateSubmit.DayOfWeek == DayOfWeek.Sunday ||x.dateSubmit.DayOfWeek == DayOfWeek.Saturday).GroupBy(b => new { b.Day, b.dateSubmit }).Select(a => a.Key.dateSubmit)
        .ToListAsync();