Sitecore 快速查询出现解析异常

发布于 2024-10-03 07:29:52 字数 497 浏览 0 评论 0原文

为什么我会收到以下代码的错误 ParseException: End of string Expected atposition 4.

代码如下:错误位于第 3 行。

var db = Sitecore.Configuration.Factory.GetDatabase("web");
string query = @"fast:/sitecore/content/foodservice/home/Products/3492-5326/3518-7";
Item item = db.SelectSingleItem(query);
return item;

我们可以使用 进行快速查询吗?代码>SelectSingleItem()?我试图避免获取文件夹内容并循环遍历每个项目,直到找到目标解决方案。建议?

Why am I getting this error with the code below ParseException: End of string expected at position 4.

Here's the code: The error is on the 3rd line.

var db = Sitecore.Configuration.Factory.GetDatabase("web");
string query = @"fast:/sitecore/content/foodservice/home/Products/3492-5326/3518-7";
Item item = db.SelectSingleItem(query);
return item;

Can we use a fast query with SelectSingleItem()? I was trying to avoid the get folder contents and loop through each item until I find the target solution. Suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻找我们的幸福 2024-10-10 07:29:52

使用 Sitecore 查询时,您需要使用破折号转义项目名称。来自 SDN

名称中带有破折号(“-”)的项目应包含在“#”符号中。请使用以下语法:/sitecore/content/Home/#About-us#。否则,您可能会收到以下错误:无效的查找源“/sitecore/content/TestSiteB/Home/About-us”:字符串结尾应位于位置 38。此外,如果项目名称包含“#”符号,则应将其包含在“#”符号中“and”或“or”一词用在“//”符号之前。例如:“/sitecore/content/Home/#news and events#//”。

更新:
我已经确认这也适用于快速查询。

End of string expected at position 27. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Sitecore.Data.Query.ParseException: End of string expected at position 27.

Source Error: 


Line 21:         protected void Page_Load(object sender, EventArgs e)
Line 22:         {
Line 23:             Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/Test-Item");
Line 24: 
Line 25:             Model = Sitecore.Context.Item;

相同的代码在 #escapes# 下运行良好:

Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/#Test-Item#");

When using Sitecore Query, you need to escape item names with dashes. From SDN:

Items with dashes in names (“-”) should be included in “#” symbols. Please use such syntax: /sitecore/content/Home/#About-us#. Otherwise you may get the following error: Invalid lookup source "/sitecore/content/TestSiteB/Home/About-us": End of string expected at position 38. Also, an item name should be included in “#” symbols if it contains “and” or “or” word and is used before “//” symbols. For example: "/sitecore/content/Home/#news and events#//".

UPDATE:
I have confirmed that this applies to Fast Query as well.

End of string expected at position 27. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Sitecore.Data.Query.ParseException: End of string expected at position 27.

Source Error: 


Line 21:         protected void Page_Load(object sender, EventArgs e)
Line 22:         {
Line 23:             Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/Test-Item");
Line 24: 
Line 25:             Model = Sitecore.Context.Item;

The same code runs fine with #escapes#:

Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/#Test-Item#");
向日葵 2024-10-10 07:29:52

这是使用 Fast Query 和 SelectSingleItem() 时的一个错误。该问题已在 Sitecore CMS 6.3.0 rev.100716 版本中修复。请参阅发行说明。由于我们使用的是 6.2,我必须重写我的方法以使用 Sitecore 查询而不是快速查询。

This is a bug when using Fast Query and SelectSingleItem(). The issue is fixed in the Sitecore CMS 6.3.0 rev.100716 release. See Release Notes. Since we are using 6.2, I had to rewrite my method to use a Sitecore Query instead of the Fast Query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文