我想返回一個狀態更新的列表,這是由插入日期按降序排序。此列表顯示在部分視圖中,因此我無法使用控制器對列表進行排序。該解決方案是創建一個服務類,包含此代碼:System.NotSupportedException當創建一個反向列表
var StatusResult = (from status in db.UserStatuses
orderby status.DateInserted
select status).Reverse().ToList();
return StatusResult;
當我運行它,我得到這個錯誤:
An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: LINQ to Entities does not recognize the method 'System.Linq.IQueryable
1[Project.Models.UserStatus] Reverse[UserStatus](System.Linq.IQueryable
1[Project.Models.UserStatus])' method, and this method cannot be translated into a store expression.
誰能幫我明白是怎麼回事,如何解決這一問題?
非常感謝。我不知道我可以在DateInserted後面寫下「降序」 –