How does Entity Framework work with recursive hierarchies? Include() seems not to work with it

前端 未结 15 1733
再見小時候
再見小時候 2020-11-28 21:53

I have an Item. Item has a Category.

Category has ID, Name, Parent

15条回答
  •  独厮守ぢ
    2020-11-28 22:29

    try this

    List list = this.GetQuery()
                    .Where(m => m.Parent == null && m.Active == true)
                    .Include(m => m.Action)
                    .Include(m => m.Parent).ToList();    
    
    if (list == null)
        return null;
    
    this.GetQuery()
        .OrderBy(m => m.SortOrder)
        .Where(m => m.Active == true)
        .Include(m => m.Action)
        .Include(m => m.Parent)
        .ToList();
    
    return list;
    

提交回复
热议问题