Sitecore Fast Query Gives Parse Exception

巧了我就是萌 提交于 2019-12-01 13:55:49

问题


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?


回答1:


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#");



回答2:


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.



来源:https://stackoverflow.com/questions/4205288/sitecore-fast-query-gives-parse-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!