2013-02-17 42 views
0

我正在運行查詢以查找「最佳時數」,最佳時數=最多訂單的小時數。
我嘗試:查詢返回大多數操作的小時數

public void ShowBestHour() 
    { 
     using (NorthwindDataContext db = new NorthwindDataContext()) 
     { 
      var query= 
       from z in db.Order_Details 
       select new 
       { 
        bestHour = z.Order.OrderDate.Value.Hour.Count() 
       }; 
     } 
    } 

我應該怎麼辦呢?

回答

1

試試這個:

public void ShowBestHour() 
{ 
    using (NorthwindDataContext db = new NorthwindDataContext()) 
    {    
     var bestHour = db.Order_Details.GroupBy(x => x.Order.OrderDate.Value.Hour).OrderByDescending(x => x.Count()).Select(x => x.Key).First(); 
    } 
}