我想运行并打印一个查询,显示一天中每小时的订单数(24)。
应该看起来像:
小时-1:00,订单数-5
小时-2:00,订单数-45
小时-3:00,订单数-25
小时-4:00,订单数-3
小时- 5:00,订单数量-43
等等……
我尝试:
public void ShowBestHours()
{
using (NorthwindDataContext db = new NorthwindDataContext())
{
var query =
from z in db.Orders
select new Stime
{
HourTime = db.Orders.GroupBy(x => x.OrderDate.Value.Hour).Count(),
};
foreach (var item in query)
{
Console.WriteLine("Hour : {0},Order(s) Number : {1}", item.HourTime, item.Count);
}
}
}
public class Stime
{
public int HourTime { get; set; }
public int Count { get; set; }
}