Querying content by document type outside of a view context
I have been feverishly trying to find the most succinct and performant ways of querying IPublishedContent like I am normally used to inside of a view context and in specific, being able to leverage collections and filters(love me some DescendantsOrSelf).
This is a nut I have been trying to crack for a while now and I fear my thinking of how to approach this is either flawed or it just cannot reasonably be done.
Given the following example - I have hundreds of nodes with the document type alias of "product" which may be nested down in a couple different areas of the site's content tree.
An example of what I would like to be able to do - In an API Controller, query for all nodes of this type and get a collection of IPublishedContent back to then do whatever with. It is the retrieving that I am stumped on.
Is there a concept relatively as simple as the following view context Model approach that can be used in an API Controller?
From an ApiController you can access the UmbracoHelper easily, but of course, it doesn't have the exact method you're after. You can though, do something like this:
YES! I was actually doing something pretty similar to this, but when I tried some of the specifics from your tip, it led me to realizing I did not have access to IsDocumentType and like I have already experienced no access to DescendantsOrSelf. Major derp moment...
Querying content by document type outside of a view context
I have been feverishly trying to find the most succinct and performant ways of querying IPublishedContent like I am normally used to inside of a view context and in specific, being able to leverage collections and filters(love me some DescendantsOrSelf).
This is a nut I have been trying to crack for a while now and I fear my thinking of how to approach this is either flawed or it just cannot reasonably be done.
Given the following example - I have hundreds of nodes with the document type alias of "product" which may be nested down in a couple different areas of the site's content tree.
An example of what I would like to be able to do - In an API Controller, query for all nodes of this type and get a collection of IPublishedContent back to then do whatever with. It is the retrieving that I am stumped on.
Is there a concept relatively as simple as the following view context Model approach that can be used in an API Controller?
Or is my thinking flawed?
Thanks a bunch!
Hey Mike,
From an ApiController you can access the
UmbracoHelper
easily, but of course, it doesn't have the exact method you're after. You can though, do something like this:Hope that helps, Tom
YES! I was actually doing something pretty similar to this, but when I tried some of the specifics from your tip, it led me to realizing I did not have access to IsDocumentType and like I have already experienced no access to DescendantsOrSelf. Major derp moment...
face palm
Might help to to reference that :)
Thanks for the input as always, Tom!
is working on a reply...