为什么即使存在具有指定字段值的项,此sitecore查询仍不返回任何项?

为什么即使存在具有指定字段值的项,此sitecore查询仍不返回任何项?,sitecore,sitecore8,Sitecore,Sitecore8,我正在尝试使用以下查询查询一个项的子项: 即使存在具有指定字段值的项,也不获取任何项 由于某些原因,查询分析器中的此查询可以工作: select * from /sitecore/content/itema/News/descendant::*[@NewsId='235271'] 在更正代码以取回我正在搜索的项目方面有什么帮助吗 string sitecoreQuery = "descendant::*[@NewsId='" + item.Id.ToString() + "']"; Item

我正在尝试使用以下查询查询一个项的子项:

即使存在具有指定字段值的项,也不获取任何项

由于某些原因,查询分析器中的此查询可以工作:

select * from /sitecore/content/itema/News/descendant::*[@NewsId='235271']
在更正代码以取回我正在搜索的项目方面有什么帮助吗

string sitecoreQuery = "descendant::*[@NewsId='" + item.Id.ToString() + "']";
Item[] newsItems = parent.Axes.SelectItems(sitecoreQuery);

根据您的评论更新:

查询看起来正常,但您也可以尝试使用子体的快捷方式:
/*
。我刚刚在本地测试了它,它返回了我期望的项目

string sitecoreQuery = "//*[@NewsId='" + item.Id.ToString() + "']";
Item[] newsItems = parent.Axes.SelectItems(sitecoreQuery);
还要仔细检查
item.Id.ToString()
是否返回您期望的Id


希望有帮助

您可以尝试以下方法:

Item[] newsItems = Sitecore.Context.Database.SelectItems(string.Format("/sitecore/content/itema/News//*[@NewsId='{0}']", NewsId));

这将为您提供筛选项目

谢谢Richard,对不起,我忘了提到newsId不是guid,只是一个数字。