Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Andreas Iseli 150 posts 427 karma points
    Mar 12, 2013 @ 16:14
    Andreas Iseli

    Accessing Published Content out of view context

    I have several services or even data repositores that wrap specific document types and folder structures for better code handling. But I'm struggling to get the content as IPublishedContent instead of IContent. I would prefer that because of the caching advantages it provides and we don't have to check if a published version exists.

    Am I right that in this case the UmbracoHelper.Content(int id) method is the one to use?

    I always start at the top and will look for a specific document types on the first level. That one contains the children the repository requires. So far I've used the content service itself, but that is too slow. Using uQuery directly also calls the database. But using the XPATH variant I think would be the best. The nodes there just again have another interface :)

    So what do you think I should take?

    The requirements are:

    - Published Content only
    - The content relies within subfolders (for optical structuring)
    - 200+ elements
    - I need to sort them after a specific date property (descending)
    - I only need the latest 5-10 entries

    My current query over the content service ist:

    IContent summaryContent = ...
    contentService.GetDescendants(summaryContent).Where(c => c.HasPublishedVersion() && c.IsMyPage()).OrderByDescending(GetDate).Take(count);

    But that one is too slow. The IsMyPage() is just a simple extension method comparing the document type. how could I adapt that to a uQuery? Something like this?

     uQuery.GetNodesByXPath("//*[@isDoc and documenttype = 'mypage']")OrderByDescending(GetNewsDate).Take(count);

    Thanks for any help :)

  • Andreas Iseli 150 posts 427 karma points
    Mar 12, 2013 @ 17:15
    Andreas Iseli

    Okay i found out that the following existing method already does the XPath translation for me and returns the nodes I want:


    And is internally translated into:


    But now my questions:

    • How to achieve to get the nodes by type only for the children of a specific node?
    • And is there a similar way to do this with IPublishedContent objects?
  • Daniël Tulp 33 posts 64 karma points
    Sep 05, 2013 @ 09:48
    Daniƫl Tulp

    children from a specific node of type MyNodeType

    uQuery.GetNode(nodeId).ChildrenAsList.Where(x => x.NodeTypeAlias == "MyNodeType")

    I never use IPublishedContent objects, only uQuery, much easier

Please Sign in or register to post replies

Write your reply to: