I can't work out whether you want to return all nodes of a particular document type underneath your baseNode, eg children of children of children at many depths, or if the nodes are all children of the base node.
If your nodes are all children of your base node then you kind of have the right approach, but there is no need to specify the level, Children (which accepts a predicate no need to add Where()) will only return nodes directly underneath your base.
var theNodes = baseNode.Children(f => f.DocumentTypeAlias == "myNodeDocType").OrderBy(f => f.CreateDate);
There is also an overload that accepts a list of document type alias:
var theNodes = baseNode.Children(new string[] { "myNodeDocType" }).OrderBy(f => f.CreateDate);
With descendants (which depending on your structure may not be an efficient way to go) the syntax is slighly different, there is an overload for Doc Type Alias or for Level but no predicate:
var theNodes = baseNode.Descendants("myNodeDocType").Where(f => f.Level == 3).OrderBy(f => f.CreateDate);
This will load all descendants of the specific type into memory, and then filter by level... so depending on your structure this might be a better overload:
var theNodes = baseNode.Descendants(3).Where(f => f.DocumentTypeAlias == "myNodeDocType").OrderBy(f => f.CreateDate);
this will get all the descendants at depth of 3, and then filter in memory by document type...
both of these approaches will be more efficient than:
Finally from a performance perspective if you've hundreds of descendants the the old fashioned XPath approach is going to be the most efficient way eg:
var nodes = Umbraco.TypedContentAtXPath("//BaseNodeAlias[@id=1102]//myNodeDocType[@level=3]");
I want to get all nodes of a certain doc type no matter what level the node is on, but the problem is that Im not allowed to use Descendants()
On the baseNode variable I dont get the property "Descendants()".
Am i using the wrong dlls?
using Umbraco.Web.Mvc;
using Umbraco.Core;
using Umbraco;
using Umbraco.Web.UI;
using Umbraco.Core.Security;
The error I get is:
"Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Descendants' and no extension method 'Descendants' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?"
Getting all nodes of certain doctype in controller
Im going nuts here trying to find a way getting all nodes under a single node that is of a certain doc type!
The nodes is on level 3 and Im not getting it to work. This is what I have so far:
I know I cant use .Children as it only gets the first level but I cant get Descendants() to work.
I must be using the wrong class or something..?
Hi Frederic
Hmmm
I can't work out whether you want to return all nodes of a particular document type underneath your baseNode, eg children of children of children at many depths, or if the nodes are all children of the base node.
If your nodes are all children of your base node then you kind of have the right approach, but there is no need to specify the level, Children (which accepts a predicate no need to add Where()) will only return nodes directly underneath your base.
There is also an overload that accepts a list of document type alias:
With descendants (which depending on your structure may not be an efficient way to go) the syntax is slighly different, there is an overload for Doc Type Alias or for Level but no predicate:
This will load all descendants of the specific type into memory, and then filter by level... so depending on your structure this might be a better overload:
this will get all the descendants at depth of 3, and then filter in memory by document type...
both of these approaches will be more efficient than:
Finally from a performance perspective if you've hundreds of descendants the the old fashioned XPath approach is going to be the most efficient way eg:
I want to get all nodes of a certain doc type no matter what level the node is on, but the problem is that Im not allowed to use Descendants()
On the baseNode variable I dont get the property "Descendants()". Am i using the wrong dlls?
using Umbraco.Web.Mvc; using Umbraco.Core; using Umbraco; using Umbraco.Web.UI; using Umbraco.Core.Security;
The error I get is: "Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Descendants' and no extension method 'Descendants' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?"
Try adding
Same error appears.
is working on a reply...