You can use either GetDescendents or fetch child pages recursively.
What's faster... depends...
In some scenarios, I had better performance with GetDescendents, and better performance with recursive methods in other secanrios.
You should measure performance and see what's best for your use-case. dotTrace or even Stopwatch class would do the trick :)
The best performance-wise solution would be to use EPiFind or some other search technology, so that you don't have to hit the EPi database.
Thanks Dejan for the insight... but i was wondering if my method of getting descendants of a specific pagetype is a good one.. Because in my mind i'm doing a lot of rep.Get<>() method calls and maybe there is a better way of getting descendants of type T .. maybe a extension method.
Another way is to use the IPageCriteriaQueryService.FindPagesWithCriteria.
// Type specified through page type ID private IEnumerable<TPageType> FindPagesByPageTypeRecursively<TPageType>(PageReference pageLink) where TPageType : IContent { var criteria = new PropertyCriteriaCollection { new PropertyCriteria { Name = "PageTypeID", Type = PropertyDataType.PageType, Condition = CompareCondition.Equal, Value = _contentTypeRepository.Load<TPageType>().ID.ToString(CultureInfo.InvariantCulture) } }; return _pageCriteriaQueryService.FindPagesWithCriteria(pageLink, criteria).Cast<TPageType>().ToList(); }
An alternative is to use IContentModelUsage.ListContentOfContentType which can give you refrerences to all content items of a certain type. This call is not cached meaning it will always cause a database roundtrip, however in most cases I would prefer it before using GetDecendents and GetContent (which on one hand is cached but on the other hand risks a whole lot more database calls and gives a much larger memory footprint).
However ListContentOfContentType will give you all references regardless of location. To get only the references that are part of a sub tree you could use IContentLoader.GetAncestors to see which lies in the subtree.
Hi Guys,
i want to search a subtree for pages of a specific pageType. I have a method for doing this, but i dont know if it's the best way of doing it performance wise..
So i want to get all the descendants of the currentpage of PageType Education..
Is this the best way of doing it?