我有'执行' X号为' ExecutiveSectionMapping'子对象取决于Executive所属的部分。
问题是,在查看这些管理员时,映射的顺序是随机的。我需要独立于订购管理人员自己来订购孩子的参数。 试过这个无济于事:
return _context.Executives
.OrderBy(x => x.ExecutiveSectionMappings.OrderBy(y=>y.ExecutiveSectionId))
.ToList();
也试过这个:
return _context.Executives
.OrderBy(x => x.ExecutiveSectionMappings.Select((y => y.ExecutiveSectionId)))
.ToList();
和此:
return _context.Executives
.Include(x=>x.ExecutiveSectionMappings.OrderBy(y=>y.ExecutiveSectionId))
.ToList();
不确定如何继续...任何想法?
答案 0 :(得分:1)
似乎这不能在你的上下文中完成,但它可以在内存中完成。
List<Executives> executives = _context.Executives.ToList();
executives.ForEach(e =>
e.ExecutiveSectionMappings = e.ExecutiveSectionMappings.OrderBy(y=>y.ExecutiveSectionId)
.ToList())