I recommend you to use Examine. It's the best performance way:
public IEnumerable<Location> GetAllLocations()
{
var examineSearcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var searchCriteria = examineSearcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.And);
var searchQuery = searchCriteria.NodeTypeAlias(Location.ModelTypeAlias);
var locations = Umbraco.TypedSearch(searchQuery.Compile()).Cast<Location>();
return locations;
}
EDIT: Don't ever use DescendantsOrSelf. If you do that from the site's root you can end up with hundreds or thousands or nodes loaded into memory.
You're right, I thought TypedSearch performed better. Still you can use Examine with Take and Skip to improve the query.
I guess it depends how many nodes you expect to have. If you have a News section for instance, that can grow a lot, I wouldn't go with the DescendantsOrSelf option or the Xpath.
Controller
Just wondering what's the best way to get all nodes of type xxx in a surface controller
Am currently using
Best approach??
Hi lori ryan
You can use Umbraco extension method DescendantsOrSelf
Hi lori ryan,
I recently found a article about the performance on the different ways of querying Umbraco : https://skrift.io/articles/archive/testing-the-performance-of-querying-umbraco/
The article is written for Umbraco 7, but i assume it's also relevant for 8.
I recommend you to use Examine. It's the best performance way:
EDIT: Don't ever use DescendantsOrSelf. If you do that from the site's root you can end up with hundreds or thousands or nodes loaded into memory.
Based on article that Lars suggested most efficient way is with Umbraco.ContentAtXPath("//xxxx");
Event DescendantsOrSelf is faster than Umbraco.TypedSearch
I have to agree with Mario that you have to be extremely careful with DescendantsOrSelf, especially with large amount of nodes.
I also remember Umbraco.ContentAtXPath being the faster one.
You're right, I thought TypedSearch performed better. Still you can use Examine with Take and Skip to improve the query.
I guess it depends how many nodes you expect to have. If you have a News section for instance, that can grow a lot, I wouldn't go with the DescendantsOrSelf option or the Xpath.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.