2

I have a people node which consists of 3500 people. Out of 3500 people 2600 items are marked as NeverPublished=True. So in Web database I have only 900 items. i want a fast query on master database which return all the items whether published or not published.

I used the following fast query

fast:/sitecore/content/Home/People//*[@@templateid='{AECD90BE-9289-4F7F-AA26-6C5ED88B6E65}']

When I am executing this fast query in Sitecore XPath window, it is returning 3500 item.

But when I am executing the same query from C# code, it is only returning 900 item. I have checked the max item setting, it is set to 0 i.e. no limit on result count

I have checked the Context Database, it is master. I have hard coded the database to master, then again getting same response.

I tried using the SQL Table approach, i.e getting all item id from SQL Table then using sitecore api fetching each item. This time again, sitecore api is returning null for NonPublishble Item.

6
  • 2
    can you add your code here? Mar 16, 2017 at 7:23
  • 1
    I bet the C# code has Factory.Database set to web
    – Abhay Dhar
    Mar 16, 2017 at 7:31
  • I bet is Sitecore.Context.Database :) Mar 16, 2017 at 7:43
  • I have checked the Context Database, it is master. I have hard coded the database to master, then again getting same response. Mar 16, 2017 at 8:10
  • I have faced the similar issue. But still didn't get any clue about it. Mar 16, 2017 at 8:17

2 Answers 2

2

Try executing your query against the master database:

var database = Sitecore.Configuration.Factory.GetDatabase("master");
var items = database.SelectItems("/sitecore/content/Home/People//*[@@templateid='{AECD90BE-9289-4F7F-AA26-6C5ED88B6E65}']");
9
  • Allow me to nitpick - your code is not setting the context database :) Mar 16, 2017 at 7:39
  • @DmytroShevchenko i have updated the answer to be more precise Mar 16, 2017 at 7:45
  • I have checked the Context Database, it is master. I have hard coded the database to master, then again getting same response. Mar 16, 2017 at 8:10
  • @NitishSrivastava have you seen this post? stackoverflow.com/questions/23411912/… also, my suggestion on troubleshooting: 1) can you try executing the database.GetItem({unpublished item id}) in the same place in your code to verify if that returns an item, 2) do you use security disabler? Mar 16, 2017 at 8:42
  • @AndreyBobrov Yes I have used Security Disabler because i wanted to change value in some fields of the item. I also tried using database.GetItem with Unpublished Item id but again got null. Mar 16, 2017 at 9:11
1

We were having the same problem. Using a normal query solved it. (Just deleting the "fast:"-part from the string.) Off course this has a performance impact, but since we can cache the result of the problem-query, it's not a big issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.