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中修改子集合需要重新创建整个集合。 –