I wonder if you can help me out. I have this structure:
Now I need to be able to query ALL "pageType" under "Folder One" which means including all the "pageType" under "Sub Folder One".
The only query I know of that gets all children and grand children is Descendants() so my current query is:
I've tested this but it only obtained all pages under "Sub Folder One". What I actually need is to obtain all the pages (pageType) under Folder One and Sub Folder One
var list1 = folderOne.ChildrenOfType("pageType").ToList();
var list2 = folderOne.ChildrenOfType("folderType").First().ChildrenOfType("pageType").ToList();
list1.AddRange(list2);
I just wanted to add that there is nothing wrong with using Descendants as long as you know what you are using it for.
Common pitfalls around it have been over using it to select a specific node from the tree with no understanding that it will iterate over the whole tree, and if its large it can be very slow.
As the documentations says you have to understand the implications.
But in many cases its very handy for example if you have for a article/category tree like this:
Article Repository
Category
-> Articles...
Category
-> Articles...
Category
-> Articles...
Then you could use Descendants to find all the articles under the repository.
It all depends on the size of the tree.
In your case I see no problem with using Descendants they way you were using it.
Alternative to Descendants()
Hello Team,
I wonder if you can help me out. I have this structure:
Now I need to be able to query ALL "pageType" under "Folder One" which means including all the "pageType" under "Sub Folder One". The only query I know of that gets all children and grand children is Descendants() so my current query is:
However, it was said that Descendants() is not performant as per this documentation: https://docs.umbraco.com/umbraco-cms/reference/common-pitfalls#querying-with-descendants-descendantsorself
If this is the case, is there an alternative instead of using Descendants() that could achieve the same result and is more performant?
Thanks.
Hi Francis
I think this is what you need:
Thank for the response Alex,
I've tested this but it only obtained all pages under "Sub Folder One". What I actually need is to obtain all the pages (pageType) under Folder One and Sub Folder One
Something like this than
list1 should contain all needed
Hi Alex,
Thank you for the suggestion. I will go ahead and give this a shot.
Regards
Hi Francis,
I just wanted to add that there is nothing wrong with using Descendants as long as you know what you are using it for.
Common pitfalls around it have been over using it to select a specific node from the tree with no understanding that it will iterate over the whole tree, and if its large it can be very slow.
As the documentations says you have to understand the implications.
But in many cases its very handy for example if you have for a article/category tree like this:
Then you could use Descendants to find all the articles under the repository.
It all depends on the size of the tree.
In your case I see no problem with using Descendants they way you were using it.
Hi Garðar,
Thank you. I appreciate the response. We're still doing some review actually and weighing our options but your input does help.
Regards,
Francis
is working on a reply...