Sitecore快速查询提供解析异常

kir*_*son 16 sitecore

为什么我使用下面的代码收到此错误 ParseException: End of string expected at position 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;
Run Code Online (Sandbox Code Playgroud)

我们可以使用快速查询SelectSingleItem()吗?我试图避免这些get folder contents and loop through each item until I find the target solution.建议?

tec*_*414 17

使用Sitecore Query时,您需要使用破折号转义项目名称.来自SDN:

名称中带破折号的项目(" - ")应包含在"#"符号中.请使用以下语法:/ sitecore/content/Home /#About-us#.否则,您可能会收到以下错误:无效的查找源"/ sitecore/content/TestSiteB/Home/About-us":位于第38位的字符串结尾.此外,如果项目名称包含在"#"符号中"和"或"或"字在"// "符号之前使用.例如:"/ 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;
Run Code Online (Sandbox Code Playgroud)

#escapes#运行相同的代码:

Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/#Test-Item#");
Run Code Online (Sandbox Code Playgroud)

  • 你可以在这里发布你的解决方案,然后为下一个有这样问题的人发布吗? (2认同)

kir*_*son 7

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