0
我試圖讓所有兒童MenuItems
與子分區直到結束,但此代碼只獲得第一級。遞歸獲取所有子類
如何將此代碼轉換爲管理該功能?
public class MenuItem : IEntityBase
{
public int Id { get; set; }
public string Text { get; set; }
public virtual ICollection<MenuItem> Children { get; set; }
public virtual MenuItem Parent { get; set; }
public bool onMenu { get; set; }
public MenuItem()
{
Children = new List<MenuItem>();
}
}
IEnumerable<Entity.MenuItem> _menuItemList = _menuItemRepository.FindByIncluding(x => x.Parent == null && x.onMenu == true, t => t.Children);
public virtual IEnumerable<T> FindByIncluding(Expression<Func<T, bool>> predicate, params Expression<Func<T, object>>[] includeProperties)
{
IQueryable<T> query = _context.Set<T>();
foreach (var includeProperty in includeProperties)
{
query = query.Include(includeProperty);
query = query.Where(predicate);
}
return query.AsEnumerable();
}