how do I sort a collection with child property?

后端 未结 2 855
暗喜
暗喜 2020-12-09 22:46

I should sort parent based on a field of child.

sample code;

IQueryable data = context.Parents.Include(o=>o.Children);
2条回答
  •  我在风中等你
    2020-12-09 22:58

    You can take one of the children names to sort by, probably select it by doing the corresponding sorting?

    Something like:

    IQueryable data = context.Parents.OrderBy(
         p=>p.Children.OrderBy(chi => chi.Name).FirstOrDefault());
    

提交回复
热议问题