Copied to clipboard

Flag this post as spam?

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


  • Lucas 13 posts 37 karma points
    Feb 07, 2012 @ 09:19
    Lucas
    1

    DynamicNode vs Node - different data in properties?

    Hi all,

    I'm currently developing an umbraco website and came across quite strange problem.

    I need to display all pages that are type of event. I'm finding them all using this code:

     

    new DynamicNode(UrlService.SiteRoot).Descendants(x => x.NodeTypeAlias == Constants.Events.DOC_TYPE_EVENT_PAGE).Items

     

    This works very well but when I'm publishing the page through CMS and later executing this code again Property values are the same - as they are cached somewhere internally and publishing refresh the cache.

    When I restart Application Pool I'm getting correct results untill...next publish.

    What is even more interesting for me is that when I used Node and not DynamicNode ... all seems to be fine...

    Please have a look at attached screenshot showing my watch in VS. 

     

    allEventsPages collection is the result of code above (collection of DynamicNodes). DateTime properties are showing 19 Feb 2012, but then I create new Node based on the ID of my dynamic node value of DateTime property is 18 Feb 2012... 

    I'm probably not aware of some internal caching for DynamicNodes... could you please advise how I can still use DynamicNodes and but avoid caching problem?

    currently I'm doing this as a workaround but it's quite bad so would like to hear some better idea:

     

     

    var allEventsPages = new DynamicNode(UrlService.SiteRoot).Descendants(
    x => x.NodeTypeAlias == Constants.Events.DOC_TYPE_EVENT_PAGE).Items.
    Select(x =>
    new DynamicNode(new umbraco.NodeFactory.Node(x.Id)))
    .ToList();

     

     

    Regards,

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 07, 2012 @ 09:36
    Jeroen Breuer
    0

    Why are you using DynamicNode in this case? It's only useful if you use DynamicNode as a dynamic object. It's just a wrapper around the Node to support dynamic stuff, but your not using that here. Doesn't answer your question, but in this case I think it's better to use the Node or make your stuff dynamic.

    Jeroen

  • Lucas 13 posts 37 karma points
    Feb 07, 2012 @ 09:46
    Lucas
    0

    To be honest I'm using DynamicNode because of the nice method - Descendants that takes lambda expression and allows me to query the whole content tree.

    If you know equivalent of this method on the Node please let me know.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 07, 2012 @ 09:48
    Jeroen Breuer
    0

    Well for the Node is always use uQuery from uComponents. Works very well :).

    Jeroen

  • Tys van den Heuvel 3 posts 23 karma points
    Sep 18, 2012 @ 14:29
    Tys van den Heuvel
    0

    When i want to use uQuery to select all nodes from a specific type i know what to do.

    But how do i select all underlying nodes of a specific type, starting from a specific node? I cannot find anything to do that. 

    Tys

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Sep 18, 2012 @ 14:51
    Hendy Racher
    0

    Hi Tys,

    You can use uQuery and Linq together, eg: (where 123 is the node id to start the search from, and 'docType' the node alias being searched for)

    IEnumerable<Node> nodes = uQuery.GetNode(123).GetDescendantNodes().Where(x => x.NodeTypeAlias == 'docType'))
    

    or use an XPath expression which is potentially much faster:

    IEnumerable<Node> nodes = uQuery.GetNodesByXPath("//*[@id='123']//docType");
    

    HTH,

    Hendy

Please Sign in or register to post replies

Write your reply to:

Draft