// Get all sub categories of current primary category
var categories = Model.Content.Children.Select(c => c.Id);
// Get company repository node
var companyRepo = Model.Content.AncestorOrSelf(1).Children.Where(
c => c.DocumentTypeAlias == "companyRepo"
).First();
// Get all companies which are children of one of the sub categories of this primary category
var companies = companyRepo.Children.Where(c => c.CheckCategories(categories.ToArray()));
Will this be good enough in terms of performance when searching over 250 companies in 30 sub categories? Or should I then use something else?
Your query is complicated!
You do not need to pick up the "companyRepo" content and then the children. You can search for docType of company.
I've never done a query when it has Nested Content, but I believe it works:
//Get all sub categories of current primary category
var categories = Model.Content.Children.Select(c => c.Id);
//Get all companies which are children of one of the sub categories of this primary category (Current Content)
var companies = Umbraco.TypedContentAtXPath("//companyDocType")
.Where(c => c.IsVisible() && c.GetPropertyValue<IEnumerable<IPublishedContent>>("packages")
.Select(s => s.GetPropertyValue<int>("category")).ContainsAny(categories));
How much performance is a very difficult question. It will depend on several factors, just testing.
When a company is published, implement the ContentService.Published method where you take the selected subcategories and creates a relationship between the company and the primary category.
Deep nested content quering
Hi all,
I need some help while quering my content structure.
Below you can find the structure:
So I have a Categorie node that contains primary categories and subcategories.
Then I have another node called Handelaar which contains companies ( which is presented as a listview ).
Now, each company has a property called Packages which is a Nested Content data type:
There you can see I have a property inside called Category. This is a multinode treepicker which can pick 1 subcategory ( no primary category ).
Now when I go to a primary category page I need to display all companies which are assigned to one of the primary subcategories.
Below takes all companies, so I need to extend this query.
Anyone that can help me out here?
Thanks in advance
/Michaël
Ok,
after some testing I have come with the following solution.
I have created a razor extension method which takes the publishedcontent node and all categories:
Then in my view I do:
Will this be good enough in terms of performance when searching over 250 companies in 30 sub categories? Or should I then use something else?
/Michaël
Hi Michaël,
Your query is complicated! You do not need to pick up the "companyRepo" content and then the children. You can search for docType of company.
I've never done a query when it has Nested Content, but I believe it works:
How much performance is a very difficult question. It will depend on several factors, just testing.
Hi Marcio,
didn't know about the ContainsAny() was searching for this yesterday.
Now I have compact the code to just:
Kind regards!
/Michaël
Suggestion is to create a way to use Relations
https://our.umbraco.org/documentation/reference/management/services/relationservice
When a company is published, implement the ContentService.Published method where you take the selected subcategories and creates a relationship between the company and the primary category.
https://our.umbraco.org/documentation/reference/events/application-startup
https://our.umbraco.org/documentation/reference/events/contentservice-events
https://our.umbraco.org/documentation/getting-started/Code/Subscribing-To-Events/
You would get the companies on the primary category page using the created relation.
I liked the challenge of your question! I wish I could help more
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.