[英]Order by descending group by Max date, then order by single row in the group by date ascending using linq Method sintax
[英]LINQ group by date descending, and order by time ascending
我有以下型號:
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-to-SQL中實現這一點,或者在執行查詢后(在結果列表中)是否必須執行此操作?
你的意思是這樣的?
IEnumerable<A> sorted = listOfA.OrderByDescending(a => a.Start.Date)
.ThenBy(a => a.Start.TimeOfDay);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.