With ContentService it was alway easy to get a node as IContent and get it's Children too. Children (or GetChildren()) is gone now. What's the best way to get all Children of a certain node when you have an IContent object?
There is a GetPagedChildren method that will return an IEnumerable of IContent items, based on the Id of a content item:
var contentId = 1234;
//is there children for this content id?
bool hasChildren = _contentService.HasChildren(contentId);
//get the first 100 children... and has an out variable giving you the total count
long totalChildren;
IEnumerable<IContent> children = _contentService.GetPagedChildren(contentId, 1, 100, out totalChildren);
//there is also a seperate ChildCount method
var childCount = _contentService.ChildCount(contentId)
V8 - IContent get Children?
With ContentService it was alway easy to get a node as IContent and get it's Children too. Children (or GetChildren()) is gone now. What's the best way to get all Children of a certain node when you have an IContent object?
Hi Remko
The ContentService has a few methods that can help you out
https://github.com/umbraco/Umbraco-CMS/blob/bf28dfe04aa2b4b9efdd83f9d5566e97954f9fba/src/Umbraco.Core/Services/Implement/ContentService.cs#L565
There is a GetPagedChildren method that will return an IEnumerable of IContent items, based on the Id of a content item:
regards
Marc
With dependency injection, you can look at Sebastiaans posts in this thread for examples on how to do this: https://our.umbraco.com/forum/umbraco-8/96270-using-umbracohelper-in-a-custom-class-in-v8#comment-304631
Regards, Magnus
Just a heads-up that the _contentService.GetPagedChildren pageIndex parameter starts at 0, so you'd technically be fetching the second page already.
Hi Marc,
Thank you.
I found the GetPagedChildren, but thought there should be any .Children() entension method.. But guess I will then have to use this one.
is working on a reply...