2010-11-17 11 views
15

Perché mi appare questo errore con il codice qui sotto ParseException: End of string expected at position 4.Sitecore Query veloce Dà Parse Eccezione

Ecco il codice: L'errore è al 3 ° riga.

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; 

possiamo utilizzare una query veloce con SelectSingleItem()? Stavo cercando di evitare i suggerimenti get folder contents and loop through each item until I find the target solution.?

+0

domanda correlata: http://stackoverflow.com/questions/3687405/escaping-reserved-words –

+0

Qualcuno sa come evitare caratteri speciali utilizzati nei campi di testo, come un apostrofo in una descrizione di un oggetto di contenuto? http://stackoverflow.com/questions/16847831/sitecore-fast-query-how-to-search-for-text-containing-special-characters-such – longda

risposta

7

questo un bug quando si utilizza Query veloce e SelectSingleItem(). Il problema è stato risolto nella release Sitecore CMS 6.3.0 rev.100716. Vedi Release Notes. Dal momento che stiamo usando 6.2, ho dovuto riscrivere il mio metodo per usare una Query Sitecore al posto della Fast Query.

+1

Appare che questo è ora un problema in 6.5.0 (versione 121009) ma per query Sitecore (ma alla posizione 5). Gioia. – longda

+0

Questo è anche un problema in Sitecore 6.6, quindi se il bug è stato corretto, è stato reintrodotto. – dadwithkids

+1

Appena rilevato in 8.1 aggiornamento 3! –

15

Quando si utilizza Sitecore Query, è necessario sfuggire ai nomi degli articoli con trattini. Da 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: mi hanno confermato che questo vale per Query veloce pure.

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; 

Lo stesso codice viene eseguito bene con # sfugge #:

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

Sto usando Sitecore Fast Query, non Sitecore Query. I trattini non sono il problema. –

+0

Sei sicuro? Hai provato a sfuggirle? Il mio istinto sarebbe che Fast Query avrebbe utilizzato la stessa logica di analisi, rendendo i trattini un requisito. – techphoria414

+0

Vedere il mio aggiornamento, abbastanza certo che i trattini sono il problema. – techphoria414

Problemi correlati