dotnet / dotnet/EntityFramework.Docs
Updating hierarchies Question
- Dominant language
- Mermaid
- Stars
- 1.7k
- Forks
- 2k
- Avg merge
- 7d 23h
- Merged PRs (30d)
- 16
Description
[Enter feedback here]
I have run this same example with a twist by updating the hierarchy so that Polo, descendant of Ponto, is actually a descendant of Mungo.
It turns out that Polo will get the same Hierarchy path as Belba "/1/2/" but I was expecting to Polo to have "/1/6/".
**How can be done?**

var poloAndDescendants = await context.Halflings.Where(
descendent => descendent.PathFromPatriarch.IsDescendantOf(
context.Halflings.Single(ancestor => ancestor.Name == "Polo").PathFromPatriarch))
.ToListAsync();
foreach (var descendent in poloAndDescendants)
{
descendent.PathFromPatriarch
= descendent.PathFromPatriarch.GetReparentedValue(
ponto.PathFromPatriarch, mungo.PathFromPatriarch)!;
}
---
#### Document Details
⚠ *Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.*
* ID: 66dfb685-054d-cf56-d93c-46f3725f4002
* Version Independent ID: 66dfb685-054d-cf56-d93c-46f3725f4002
* Content: [Microsoft SQL Server Database Provider - Hierarchical Data - EF Core](https://learn.microsoft.com/en-us/ef/core/providers/sql-server/hierarchyid?tabs=visual-studio)
* Content Source: [entity-framework/core/providers/sql-server/hierarchyid.md](https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/providers/sql-server/hierarchyid.md)
* Product: **entity-framework**
* Technology: **entity-framework-core**
* GitHub Login: @ajcvickers
* Microsoft Alias: **avickers**
Contributor guide
Assessment
This issue has not been assessed yet.