2013-02-07 52 views
0

選一個會如何排序使用LINQ以下方法Sitecore的子項的列表,並轉換/鑄造的「排序列表」回Sitecore.Data.Items.Item[]Sitecore的項目/分項使用LINQ

... 
Sitecore.Data.Items.Item[] subitems = current.SelectItems(query); 
var sortedList = (from entry in subitems orderby entry.Fields["Title"].Value ascending select entry); 
... 

注:我嘗試在查詢中對其進行排序失敗。

回答

1

您不需要項目中的.Field。只要使用直接使用[「標題」],例如:

Sitecore.Data.Items.Item[] subitems = current.SelectItems(query); 
Sitecore.Data.Items.Item[] sorted = subitems.OrderBy(i => i["Title"]).ToArray(); 
+0

約定的價值,更安全訪問字段值這種方式。 –

+0

沒有機會爲可以爲空的字段獲取空引用異常。 – Younes