dotnet / dotnet/EntityFramework.Docs

Updating hierarchies Question

Open
#4,622 0 comments 0 reactions 0 assignees View on GitHub
area-save-changes
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?**

![Hierachy](https://github.com/dotnet/EntityFramework.Docs/assets/92387946/30b67ca2-ad00-4674-9bbe-278b11db2a99)

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.