I haven't used Linq2Umbraco yet, but I know with the Document API you can do something like this:
Document doc = new Document(1234); foreach (Document d in doc.Children.Where(n => n.ContentType.Alias.ToString() == "YourDocTypeAlias")) { }
I don't think there's a similar way to do this using nodeFactory though (short of looping through all children and adding a condition inside the loop to check the NodeTypeAlias)
You can also find (some) information in the API Cheatsheet section of the wiki.
FYI, in uComponents there's a helper library called uQuery that adds XPath axis type extension methods to the Node and Media objects, allowing their tree structure to queryable with Linq.
using System.Linq; using umbraco.presentation.nodeFactory; using uComponents.Core.uQueryExtensions;
The umbraco.presentation.nodeFactory namespace is required, as GetChildNodes() is an extension method on the Node object, and the .NodeTypeAlias is a property of Node.
How to get all child nodes with particular type
Hi all,
Do you know how to get all child nodes with a particular type for example,
I want to get all news item in particular category.
I try to do it in umbraco.linq.
newsCat.NewsItems.ToList();
but give me this error
The given key was not present in the dictionary
So I try to find solution in using Umbraco API ?
Is there any good documentation for umbraco API ?
Thanks
Hi Kurniawan
Seems like the reference to the API documenatation was lost with the launch of the new umbraco.org website. However in this post http://our.umbraco.org/forum/developers/api-questions/13618-Where-did-the-API-documentation-go you can get af .chm file on 41MB that contains the documentation.
Hope thils helps.
/Jan
Hi,
I haven't used Linq2Umbraco yet, but I know with the Document API you can do something like this:
I don't think there's a similar way to do this using nodeFactory though (short of looping through all children and adding a condition inside the loop to check the NodeTypeAlias)
You can also find (some) information in the API Cheatsheet section of the wiki.
-Tom
Hi,
FYI, in uComponents there's a helper library called uQuery that adds XPath axis type extension methods to the Node and Media objects, allowing their tree structure to queryable with Linq.
HTH,
Hendy
Thanks Guys,
But Do you know how to get all child inheritly using linq ?
Actually we can do looping (while loop), but is it possible using linq ?
Thanks
Hendy,
isn't this namespae obsolete?
Hi Andrew,
The umbraco.presentation.nodeFactory namespace is required, as GetChildNodes() is an extension method on the Node object, and the .NodeTypeAlias is a property of Node.
Cheers,
Hendy
Hi Andrew,
You're totally right, the namespace isn't needed at all provided you don't directly instantiate a Node object - had assumed otherwise.
Cheers,
Hendy
is working on a reply...