var list = dbcontext.StudentProfiles.GroupBy(u => u.CreatedDate.Value.Month)
.Select(u => new UserData
{
// UserCount = u.Count(),
Month = u.FirstOrDefault().CreatedDate.Value.Month.ToString()
// UserCount = dbcontext.StudentProfiles.Where(u => u.CreatedDate.Value.Month ==0).Count()
UserCount = dbcontext.StudentProfiles.Where(u => u.CreatedDate).Count()
}).ToList();
我需要根据其注册日期显示月度计数,例如:1月:23、2月:86、3月:45等……。
答案 0 :(得分:0)
您可以执行以下操作:
var list = dbcontext.StudentProfiles.GroupBy(u => u.CreatedDate.Value.Month)
.Select(group => new UserData
{
Month = group.Key.ToString(),
UserCount = group.Count()
}).ToList();