0
我需要帶回有序的'ExecutiveSections',它有一個'sortOrder',以及chld-objects'ExecutiveSectionMappings',它們也有一個'sortOrder'。LINQ:訂購子對象
我需要對兩者進行排序,以便各部分按照它們各自的映射排列在它們下面(映射中有'管理人員'本身)。因此它顯示在網站上,部分由管理人員按正確順序排列。
到目前爲止,我曾嘗試:
var sections = _executiveSectionRepository.GetExecutiveSections()
.OrderBy(x => x.SortOrder)
.ThenBy(x => x.ExecutiveSectionMappings.Select(c => c.SortOrder));
和:
var sections = _executiveSectionRepository.GetExecutiveSections()
.OrderBy(x => x.SortOrder)
.ThenBy(x => x.ExecutiveSectionMappings.Select(c => c.SortOrder).FirstOrDefault());
這隻訂單ExecutiveSections,而不是ExecutiveSectionMappings ... 我缺少什麼?
爲什麼不能'GetExecutiveSections'被修改爲返回正確排序的子對象?在LINQ中修改子集合需要重新創建整個集合。 –