Copied to clipboard

Flag this post as spam?

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


  • Philip 59 posts 73 karma points
    Jun 18, 2012 @ 13:58
    Philip
    0

    Retrieving a list of documents by a list of IDs

    I am creating some statistics on documents, and have a list returned with the IDs of multiple documents.

    Is there an API method for Umbraco 4.7.1 by which I can return a list of the documents in one go, instead of having to do a roundtrip to the database for each document I want to retrieve?

    E.g. something else than

    foreach(var id in IDs)
    {
    documents.Add(new Node(id));
    }

     

     

  • Jamie Pollock 174 posts 853 karma points c-trib
    Jun 18, 2012 @ 14:18
    Jamie Pollock
    0

    Hi Philip,
    I don't think there is any way to avoid it. Also in what context are you using this code? And what do you want to return DynamicNodes, Nodes or Documents? All 3 whilst referencing the same content actually structure the data a bit differently.

    Razor offers Library.NodesById(object[] ids) and that returns a DynamicNodeList. As for non-Razor there isn't anything that springs to mind without using the above code you have.

    Jamie

  • Philip 59 posts 73 karma points
    Jun 18, 2012 @ 14:34
    Philip
    0

    I tried to edit my post, but I receive an XSLT error. The version number I am using is 4.7.2.

    The data/context is an external database which will have the list of the IDs. I then have a repository method which retrieves the IDs from the external database and then the documents which corresponds to the IDs. Since all of this is done in a library, I don't have access to the Razor syntax. Would this mean that I would have to implement my own overload of "new Node(List<int> Ids)"?

    I am new to Umbraco, and can't find documentation on the differences between the DynamicNode and the 'regular' node, so I don't know if the DynamicNode would be more appropriate.

     

  • Jamie Pollock 174 posts 853 karma points c-trib
    Jun 18, 2012 @ 14:57
    Jamie Pollock
    0

    Hi Philip
    Well the jist of it, so far as I understand it is:

    • Document - these are content nodes which can be both published & unpublished. This data is coming from the DB.
    • Node - these are exclusively published nodes, so it's not possible to get unpublished Node class objects because the data is cached.
    • DynamicNode - similar to Node but used within the Razor DynamicNodeContext

    I could be missing some other subtle differences there or completely wrong about DynamicNode. In most cases unless you're dealing with the backoffice you'd be fine using Node & DynamicNode for frontend purposes. If you're trying to avoid the DB then you could consider the latter two as this is cached data.

    Without being able to use the Razor library NodesById then you'd have to go down the other route. You could consider the overload approach. I would suggest making a helper method which returns a list of nodes based on the array of ids or a comma separated string. That doesn't prevent the round trips though. So to answer your original question, I don't believe there is a way if the answer is you need to use Document.

    Jamie

Please Sign in or register to post replies

Write your reply to:

Draft