How to get Document's Parent's Document Type Alias
I want to walk up a Document's parent tree looking for one of a certain DocumentType. Document's Parent property is a CMSNode object which doesn't seem to have anything indicating what document type it is. Is there a way to find the Parent's document type alias without having to instantiate a new Document with the parent's id and incurring another big database call?
As I wrote in another answer, you should not use document unless you need to change something on it. Do the tree walking using nodefactory and only instantiate a document when you're certain you will change the data in it.
For certain parts of my application I need to get at the latest saved content. As I understand it using the nodefactory node's limits you to only published content. If there is a way to get saved content via the nodefactory I would much prefer to go that route. Is there a way to do that?
Document.Parent is a CMSNode and not a Document. So the only way I see to do it is: new Document(myDoc.Parent.Id).ContentType.Alias. This is functional but I plan on using this to walk up the document tree searching for a document of a certain type so I am hoping there is a way to do this without having to instantiate a whole new Document since it incurrs a fairly expensive DB call.
Dear Mr. Green Giant (how do one address anyone with such name? ;-) )
yes, if you work with unpublished content you will need to use the document tree. But, if this happens fairly often I think that you can benefit from writing your own stored procedure to locate the document you need and then load it as a document based on the id, rather than loading documents until you find the one you're looking for.
How to get Document's Parent's Document Type Alias
I want to walk up a Document's parent tree looking for one of a certain DocumentType. Document's Parent property is a CMSNode object which doesn't seem to have anything indicating what document type it is. Is there a way to find the Parent's document type alias without having to instantiate a new Document with the parent's id and incurring another big database call?
As I wrote in another answer, you should not use document unless you need to change something on it. Do the tree walking using nodefactory and only instantiate a document when you're certain you will change the data in it.
Harald,
For certain parts of my application I need to get at the latest saved content. As I understand it using the nodefactory node's limits you to only published content. If there is a way to get saved content via the nodefactory I would much prefer to go that route. Is there a way to do that?
Hi, use documents for that (slower than nodefactory since it's using db call(s) for each doc):
http://our.umbraco.org/wiki/reference/api-cheatsheet/enumerating-documents
(.Parent works too)
HTH / Jonas
Document.Parent is a CMSNode and not a Document. So the only way I see to do it is: new Document(myDoc.Parent.Id).ContentType.Alias. This is functional but I plan on using this to walk up the document tree searching for a document of a certain type so I am hoping there is a way to do this without having to instantiate a whole new Document since it incurrs a fairly expensive DB call.
Dear Mr. Green Giant (how do one address anyone with such name? ;-) )
yes, if you work with unpublished content you will need to use the document tree. But, if this happens fairly often I think that you can benefit from writing your own stored procedure to locate the document you need and then load it as a document based on the id, rather than loading documents until you find the one you're looking for.
If creating your own sql statement to find the documents might be an option then I can recommend http://blog.hendyracher.co.uk/wp-content/uploads/Umbraco-Schema-with-Constraints-v2.gif. For a full diagram see http://www.farmcode.org/post/2010/06/15/Umbraco-41-Database-Structure.aspx
Cheers,
Harald
is working on a reply...