Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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?
Model.Content.DescendantsOrSelf().Where(x => x.DocumentTypeAlias == "product");
Or is my thinking flawed?
Thanks a bunch!
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:
var products = Umbraco.TypedContentAtRoot()
.First(n => n.IsDocumentType("Homepage"))
.First(n => n.IsDocumentType("ProductArea"))
Hope that helps,
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...
Might help to to reference that :)
Thanks for the input as always, Tom!
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted