我的课程如下,
public class SiteActionMap
{
public int Id { get; set; }
public string ImageName { get; set; }
public int ParentId { get; set; }
public string Name { get; set; }
public virtual ICollection<SiteActionMap> Childrens { get; set; }
public virtual SiteActionMap Parent { get; set; }
public bool Active { get; set; }
}
我希望得到一份按孩子计算的订单列表。
我正在尝试这样的事情,但我没有工作。
List<SiteActionMap> list = dbContext.SiteActionMap
.Include(m => m.Childrens)
.Include(m => m.Parent)
.OrderBy(i => i.Childrens.Count)
ToList();
我如何根据孩子的数量对我的名单进行排序?
答案 0 :(得分:4)
添加lbruder所说的,在这种情况下不计算一个方法()吗?
List<SiteActionMap> list = dbContext.SiteActionMap
.Include(m => m.Childrens)
.Include(m => m.Parent)
.OrderByDescending(i => i.Childrens.Count())
.ToList();
答案 1 :(得分:2)
List<SiteActionMap> list = dbContext.SiteActionMap
.Include(m => m.Childrens)
.Include(m => m.Parent)
.OrderByDescending(i => i.Childrens.Count)
.ToList();