I have one entity like this:
public string Name { get; set; }
public string Description { get; set; }
public Guid? ParentId { get; set; }
public int Position { get; set; }
public bool IsVisible { get; set; }
public virtual Category ParentCategory { get; set; }
public virtual ICollection<Category> Categories { get; set; }
public virtual ICollection<Product> Products { get; set; }
In database i insert it like this:
Category1
{
Category2
{
Category4
}
Category3
}
How should look entity query to get all Category with ALL children? I traing like this:
var category = await _context.Categories
.Include(x => x.Categories)
.ThenInclude(x=>x.Categories)
.OrderBy(x => x.Position).FirstAsync(x => x.ParentId == null);
But i think this isn't good way becouse i don't know deep will be this tree.