使用我在网上找到的示例,我创建了一个函数,该函数使用 GetReparentedValue 重新设置子项。
但是,当我运行代码时,出现以下错误:无法在对象中插入重复键。
我明白为什么(因为我正在尝试让孩子重新成为父母,而新父母已经有了孩子,所以我需要知道新父母结构中孩子的 MAX 路径(层次结构),但我不明白我实际上是怎样的打算这样做。
路径 0x58
旧路径 0x
新路径 0x68
SqlCommand command = new SqlCommand("UPDATE Structure SET " +
"Path = " + path + ".GetReparentedValue" +
"(" +
oldPath + ", " + newPath +
")" +
"ParentID = @id " +
"WHERE Path = " + path, _connection);
添加孩子时我必须这样做,所以我认为需要将其添加到上面的查询中,但我不知道在哪里path + ".GetDescendant(" + lastChildPath + ", NULL)
数据库表
StructureID int Unchecked
Path hierarchyid Unchecked
PathLevel ([Path].[GetLevel]()) Checked
Description nvarchar(50) Checked
ParentID int Checked
ParentPath ([Path].[GetAncestor]((1))) Checked
有人有什么建议吗?
提前感谢您的帮助:-)
克莱尔