我想通過一個日期時間字段,列表中包含的對象命令:爲什麼orderBy不適用於此linq表達式?
// Order search results (posts to be displayed by created datetime).
if (implicitSelectedVisualiser.PostsSortOrder == PostsSortOrder.CREATED_DATE_ASC)
approvedSearchResults.OrderBy(s => s.PostCreatedTime);
else
approvedSearchResults.OrderByDescending(s => s.PostCreatedTime);
的問題是,沒有東西來分類的。
初始順序是:
2013-06-28 19:52:08.000
2013-06-28 19:38:30.000
2013-06-28 18:35:37.000
2013-06-29 17:07:22.000
2013-07-01 19:12:44.000
2013-07-01 19:15:29.000
2013-07-01 23:51:11.000
從上述排序(那張DESC)後,它仍然相同,而這完全在SQL。
SELECT [PostCreatedTime]
FROM [SearchResults]
Where SearchQuery_Id = 10 or SearchQuery_Id = 7
Order by PostCreatedTime desc
2013-07-01 23:51:11.000
2013-07-01 19:15:29.000
2013-07-01 19:12:44.000
2013-06-29 17:07:22.000
2013-06-28 19:52:08.000
2013-06-28 19:38:30.000
2013-06-28 18:35:37.000
我在我的linq中犯了什麼錯誤?
你確定'implicitSelectedVisualizer.PostsSortOrder!= PostsSortOrder.CREATED_DATE_ASC'? –