I have This object
public class ParentGroup
{
public int Id { get; set; }
public ParentGroup Parent { get; set; }
public int? ParentId { get; set; }
public ICollection<ParentGroup> Children { get; set; }
public ParentGroupType ParentGroupType { get; set; }
public int? ParentGroupTypeId { get; set; }
public bool Active { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}
I'm trying to get all the parent with all the children but there is a something that happened with me and I can't understand if I put the where filter in the query I can't get all the data related to the children I got only the first level
If I removed it I get all the date with all the levels and I don't want to make the query to the DB, not my memory
This my code
public async Task<List<ParentGroup>> GetOrganizationStructureTree()
{
// var query = _context.ParentGroups.Where(x => x.ParentId == null);
List<ParentGroup> ParentGroups = await _context.ParentGroups.Include(par => par.Children).Include(par => par.Parent).Include(pr => pr.ParentGroupType).ToListAsync();
return ParentGroups;
}