Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Craig100 1136 posts 2523 karma points c-trib
    May 22, 2020 @ 19:01
    Craig100
    0

    ContentService GetChildren

    Umb 8.6.1

    Upgrading the code from a V7 site to V8 I have a class called by an UmbracoApiController which needs to get a list of children of a particular node.

    To get the ContentService I've had to use :-

    using Umbraco.Core.Composing;
    IContentService contentService = Current.Services.ContentService;
    

    which is not what the docs say here: https://our.umbraco.com/documentation/reference/management/services/contentservice/

    However, contentService only has a GetPagedChildren, it doesn't have the old GetChildren which V7 did.

    All I want this for is to hold in an array or list so I can compare a value in each child with the value I get from the API to see if it exists.

    Is there a better way to do this? I'm also aware that this is looking at the DB directly. I have a suspicion there's a way to look at the cache instead which would be quicker but can't find any info.

    Any comments or advice would be appreciated.

    / Craig

  • Yakov Lebski 594 posts 2350 karma points
    May 22, 2020 @ 20:05
    Yakov Lebski
    100

    You can do it in this way

    Services.ContentService.GetPagedChildren(parentId, 0, int.MaxValue, out var count)
    
  • Craig100 1136 posts 2523 karma points c-trib
    May 22, 2020 @ 20:59
    Craig100
    0

    Thanks, that looks like it'll work.

    It beats me why we don't have the simple cases of GetChildren() and GetDescendants(), but hey ho.

    Cheers,

    / Craig

  • 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.

Please Sign in or register to post replies