【问题标题】:Sitecore Fast Query Gives Parse ExceptionSitecore 快速查询导致解析异常
【发布时间】:2010-11-17 14:20:56
【问题描述】:

为什么我在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. 建议?

【问题讨论】:

标签: sitecore


【解决方案1】:

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

名称中带有破折号(“-”)的项目应包含在“#”符号中。请使用这样的语法:/sitecore/content/Home/#About-us#。否则您可能会收到以下错误: Invalid lookup source "/sitecore/content/TestSiteB/Home/About-us": End of string expected at position 38. 此外,如果项目名称包含,则应包含在“#”符号中“and”或“or”字and用在“//”符号之前。例如:“/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#");

【讨论】:

  • 我使用的是 Sitecore 快速查询,而不是 Sitecore 查询。破折号不是问题。
  • 你确定吗?你试过逃避他们吗?我的直觉是,Fast Query 将使用相同的解析逻辑,因此需要使用破折号。
  • 我很肯定这不是破折号。我的错误在第 4 位,并且它周围没有破折号。我使用了另一种解决方案。谢谢!
  • 您能否在此处为遇到此类问题的下一个人发布您的解决方案?
  • 要回答我上面的问题 - 可以简单地将路径中的所有破折号替换为由哈希 (#) 包围的破折号,例如:item.Paths.Path.Replace("-", "#-#")
【解决方案2】:

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

【讨论】:

  • 似乎这现在是 6.5.0 (rev. 121009) 中的一个问题,但对于 Sitecore 查询(但在位置 5)。喜悦。
  • 这也是 Sitecore 6.6 中的一个问题,所以如果 bug 得到修复,它会重新引入。
  • 我们正在使用 8.1 更新 2 并且也遇到了这个问题。如果查询以“fast:”或“query:”为前缀,则根本不起作用。
  • 在 Sitecore 9.2 上仍然是一个问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-31
  • 1970-01-01
  • 2020-01-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多