In my .NetCore3 project, I use HierarchyId to implement data tree structure. I am successful in storing as a tree, But I have trouble getting children.
MyModel :
public int Id { get; set; }
[Required]
[StringLength(256)]
public string Name { get; set; }
public HierarchyId Level { get; set; }
And My Problem : My code is written for the return of children
var parentCategory = Context.HierarchyBOMs
.AsQueryable()
.FirstOrDefault(x => x.Id == id);
var childCategoryQuery = Context.HierarchyBOMs
.AsQueryable()
.Where(x => x.Level.GetAncestor(1) == parentCategory.Level);
var childList = childCategoryQuery.ToList();
But this code only returns one child.
How can all children be returned?