Sitecore Axes.IsDescendatof/Axes.IsAncestorOf-包括在内?

Sitecore Axes.IsDescendatof/Axes.IsAncestorOf-包括在内?,sitecore,sitecore6,items,Sitecore,Sitecore6,Items,对于Item.Axes.isDescendatof()和Item.Axes.IsAncestorOf(),我是否缺少Sitecore返回true的原因或内容 //正确 //真的 编辑:任何人可能会偶然发现这个答案,寻找非包容性的IsAncestorOf或isdescendatof,下面是几个例子,我需要在新闻类别的多选字段中找到最高级别的元素 newsCategories .Where(x => newsCategories .Any(y

对于
Item.Axes.isDescendatof()
Item.Axes.IsAncestorOf()
,我是否缺少Sitecore返回
true
的原因或内容

//正确
//真的

编辑:任何人可能会偶然发现这个答案,寻找非包容性的
IsAncestorOf
isdescendatof
,下面是几个例子,我需要在新闻类别的多选字段中找到最高级别的元素

newsCategories
   .Where(x => newsCategories
                       .Any(y => x != y && !x.Axes.IsDescendantOf(y)))

您在Sitecore逻辑中遇到了“故障保护”。
这是因为您正在对同一项进行自我检查。您需要使用两个不同的项来执行此操作以产生任何结果。

我必须相信Sitecore中的方法不应被命名为
IsAncestorOf
isdescendatof
。根据您的发现并快速查看Sitecore代码,这些方法应该真正命名为
IsAncestorOrSelf
isdescendatorself

比如说,

Sitecore.Data.Items.Item x = //some item;
Sitecore.Data.Items.Item y = //some item;
x.Axes.IsAncestorOf(y)
x.Axes.IsDescendantOf(y)
IsAncestorOf
方法正在比较
x.ID==y.ID
。然后,它会将
x.ID
与y的父项的
ID
进行比较,这就是为什么它应该被命名为
IsAncestorOrSelf

如果
x
LongID
路径以
LongID
路径
y
开始,则
isdiscendatof
方法将进行比较。由于字符串总是以相同的字符串开头,我们再次看到此方法应命名为
isDescendatorSelf


仅供参考,
LongID
路径看起来像这样
/{11111111111-1111-1111-111111111}/{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}
,我怀疑是为了避开sitecore允许兄弟姐妹同名的事实而使用的,你知道为什么它是故障保护或用例吗?我对答案很好奇。我注意到他们正在比较这两个项目的ID,但没有检查它们是否是反编译源中的相同项目。这两个项目如何具有相同的ID但却是相同的项目?除非您以某种方式在语言和/或数据库中进行分解。
string longID=this。_item.path.longID;字符串str2=item.path.LongID;返回longID.StartsWith(str2)isDescendatorSelf
方法。为了说明这一点,我在Sitecore 7.2中查看ItemPath.IsAncestorOf的源代码(ILSpy)时记录了Sitecore的问题。看起来这是固定的。比较从参数的父项开始。真正让我困惑的是参数命名:IsAncestorOf(ancestorItem),其中ancestorItem是(或不是)后代。IsDescendatof(DegenantItem)也是如此,其中DegenantItem是(或不是)祖先。两者都应命名为“项”。
newsCategories
   .Where(x => newsCategories
                       .Any(y => x != y && !x.Axes.IsDescendantOf(y)))
Sitecore.Data.Items.Item x = //some item;
Sitecore.Data.Items.Item y = //some item;
x.Axes.IsAncestorOf(y)
x.Axes.IsDescendantOf(y)