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)); }
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.
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.
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.
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
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
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.
Hi Philip
Well the jist of it, so far as I understand it is:
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
is working on a reply...