尝试这个
var query =
from f in File
where f.DateCreated > DateTime.Now.AddDays(-7)
group f by new { Day = f.DateCreated.Day, DayOfWeek = f.DateCreated.DayOfWeek } into g
select new
{
Day = g.Key.Day,
DayOfWeek = g.Key.DayOfWeek.ToString().Substring(0, 3),
Count = g.Count()
};
如果您需要特定于文化的名称,您可以使用Date.ToString("dddd", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"))
:
var query =
from f in File
where f.DateCreated > DateTime.Now.AddDays(-7)
group f by new { Day = f.DateCreated.Day, DayOfWeek = f.DateCreated.ToString("dddd", System.Globalization.CultureInfo.CreateSpecificCulture("en-US")) } into g
select new
{
Day = g.Key.Day,
DayOfWeek = g.Key.DayOfWeek.Substring(0, 3),
Count = g.Count()
};
更新:
好的,我不是 VB 专家,但是对于 VB,你可以尝试这样的事情
Dim query =
From f In File
Where f.DateCreated > DateTime.Now.AddDays(-7)
Group f By Day = f.DateCreated.Day, DayOfWeek = f.DateCreated.DayOfWeek.ToString().Substring(0, 3)
Into Group, Count = Count()