2012-01-06 121 views
3

我有以下型號:LINQ集團按日期倒序排列,並且爲了按時間升序

public class A 
{ 
    public int? Id {get;set;} 
    public DateTime Start {get;set;} 
    public DateTime End {get;set;} 
} 

現在我想組按日期的所有條目,每日期降序排序,並且每次遞增排序(使用LINQ)。示例輸出:

Jan 3. 2012 
-- 10:00-11:00 
-- 11:00-13:00 
Jan 2. 2012 
-- 10:00-11:00 
-- 12:00-15:00 
Jan 1. 2012 
-- 9:00-10:00 
-- 12:00-13:00 

是否有可能實現這一目標的LINQ到SQL或我有這個查詢(結果列表)執行之後?

+0

「開始」和「結束」只是DateTime條目,例如,想象一個時間表。 – Marthijn 2012-01-06 13:20:58

回答

7

您的意思是?

IEnumerable<A> sorted = listOfA.OrderByDescending(a => a.Start.Date) 
           .ThenBy(a => a.Start.TimeOfDay); 
+0

謝謝,但遇到以下錯誤:'指定的類型成員'Date'在LINQ to Entities中不受支持。只支持初始值設定項,實體成員和實體導航屬性。「所以我把你的代碼放在查詢執行後,它工作正常:) – Marthijn 2012-01-06 13:17:24