Within our organisation we are keen to be using the latest API methods (nothing obsolete or scheduled to be removed with V7).
With that in mind following discussions with members of the umbraco HQ team we have started to factor out the use of the uQuery component.
My question is this: uQuery made use of the Node classes within umbraco.NodeFactory. Is it favourable to use these classes or stick to using IPublishedContent?
Node has methods for easy Id retrieval whereas IPublishedContent requires us to implement our own logic for locating valid documents within umbraco.config.
Not quite sure I understand the question, but I'd recommend going for IPublishedContent.
It's all "just cached XML" behind the scenes anyway, and the media is in a Lucene index.
To query it you just use the Enumerable/Queryable extensions.
For instance content.Children().Where(c => c.Alias == "someDocumentType") or even use a core extension: content.Children().Where(c => c.IsDocumentType("someDocumentType").
At the risk of doing too much blatant self-promotion, you should also have a look at the typed model stuff I'm (we're) doing: https://github.com/lars-erik/Umbraco.CodeGen / http://our.umbraco.org//projects/developer-tools/umbraco-codegen
With it, you can start doing content.Children().OfType<Article>() or content.Descendants.OfType<Article>(), add .Where(m => m.StronglyTypedProperty == "whatever") etc.
(Won't be 100% nice until a future 6.x release)
Thanks for the reply Lars. I'll have a look into your link, from what you say your new code would be very useful (can't wait for you to release it ;))
IPublishedContent is the way to go as you say, its unfortunate that there are no GetById / GetRootNode methods associated with it but I've just noticed that the UmbracoHelper class gives us access to all the goodness that we require e.g.
Regarding the codegen plugin. It's finished and released with regards to generating and parsing typed models, but it won't be as easy to use (without some plumbing) until the core team has done a couple of tweaks in the core.
Umm.. Forgot to mention, if you're using MVC, all your views have UmbracoHelper as a property called Umbraco.
So in your views, you can just do @Umbraco.TypedContent(id).Url etc.
Node usage question
I'm after some best practice advice.
Within our organisation we are keen to be using the latest API methods (nothing obsolete or scheduled to be removed with V7).
With that in mind following discussions with members of the umbraco HQ team we have started to factor out the use of the uQuery component.
My question is this: uQuery made use of the Node classes within umbraco.NodeFactory. Is it favourable to use these classes or stick to using IPublishedContent?
Node has methods for easy Id retrieval whereas IPublishedContent requires us to implement our own logic for locating valid documents within umbraco.config.
Any advice would be really appreciated.
Chris Whittington
Not quite sure I understand the question, but I'd recommend going for IPublishedContent.
It's all "just cached XML" behind the scenes anyway, and the media is in a Lucene index.
To query it you just use the Enumerable/Queryable extensions.
For instance
content.Children().Where(c => c.Alias == "someDocumentType")
or even use a core extension:content.Children().Where(c => c.IsDocumentType("someDocumentType")
.At the risk of doing too much blatant self-promotion, you should also have a look at the typed model stuff I'm (we're) doing:
https://github.com/lars-erik/Umbraco.CodeGen / http://our.umbraco.org//projects/developer-tools/umbraco-codegen
With it, you can start doing
content.Children().OfType<Article>()
orcontent.Descendants.OfType<Article>()
, add.Where(m => m.StronglyTypedProperty == "whatever")
etc.(Won't be 100% nice until a future 6.x release)
Thanks for the reply Lars. I'll have a look into your link, from what you say your new code would be very useful (can't wait for you to release it ;))
IPublishedContent is the way to go as you say, its unfortunate that there are no GetById / GetRootNode methods associated with it but I've just noticed that the UmbracoHelper class gives us access to all the goodness that we require e.g.
You're right on track. :)
IPublishedContent
also have a couple of nice extensions to navigate upwards.content.AncestorOrSelf("rootAlias")
< should be your root. (orAncestorOrSelf(<level>)
)Full list of extensions here:
http://our.umbraco.org/documentation/Reference/Mvc/querying
Regarding the codegen plugin. It's finished and released with regards to generating and parsing typed models, but it won't be as easy to use (without some plumbing) until the core team has done a couple of tweaks in the core.
L-E
Umm.. Forgot to mention, if you're using MVC, all your views have UmbracoHelper as a property called Umbraco.
So in your views, you can just do
@Umbraco.TypedContent(id).Url
etc.is working on a reply...