Sitecore快速查询提供解析异常

时间:2010-11-17 14:20:57

标签: 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;

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

2 个答案:

答案 0 :(得分: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;

使用#escapes#:

运行相同的代码
Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/#Test-Item#");

答案 1 :(得分:7)

使用Fast Query和SelectSingleItem()时,这是一个错误。 Sitecore CMS 6.3.0 rev.100716版本中已修复此问题。见Release Notes。由于我们使用的是6.2,因此我必须重写我的方法以使用Sitecore查询而不是快速查询。

相关问题