public static HierarchyId GeneratePathForChild(HierarchyId? parent, HierarchyId? lastChildId){ //Handling Fatherless Entities. if (parent is null) return HierarchyId.Parse("/"); //Handling Entities With No Sister Entities. if (lastChildId is null) return HierarchyId.Parse($"{parent}{1}/"); //Handling Entities With Sister Entities var lastDigit = lastChildId.ToString().Split("/", StringSplitOptions.RemoveEmptyEntries).Last(); var lastDigitNumber = int.Parse(lastDigit); return HierarchyId.Parse($"{parent}{lastDigitNumber + 1}/");}