Copied to clipboard

Flag this post as spam?

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


  • Robert 33 posts 173 karma points
    May 17, 2018 @ 10:21
    Robert
    0

    Using filter param of content service GetPagedChildren

    I am using the GetPagedChildren method of the contentservice backoffice api. I want to return my paged children only where a property of that object is equal to a certain value, in this case where the Property "Active" is true.

    I see that the last param of this method is called filter so I do this:

    .contentService.GetPagedChildren(parentId, pageIndex, pageSize, out total, filter: "Active == true")

    But passing "Active == true" doesn't work - no results come back. Is this correct use and syntax for filter param? Can I use it like this?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    May 17, 2018 @ 12:05
    Dan Diplo
    1

    You can see how it works from the source code:

    if (filter.IsNullOrWhiteSpace() == false)
    {
        filterQuery = Query<IContent>.Builder.Where(x =>x.Name.Contains(filter));
    }
    

    So it looks like it's doing more of a substring match on the value of name - so it's more of a "search term" rather than a conditional filter, I think.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    May 17, 2018 @ 13:45
    Dave Woestenborghs
    0

    Hi Robert,

    Is this code for rendering information on the front end ?

    Than I would strongly suggest you not to use the content service.

    This hits the Umbraco Database and bypasses the cache, which can lead to perfomance problems.

    If it is for rendering on the front end have a look at the documentation here : https://our.umbraco.org/documentation/Reference/Querying/

    Dave

  • Robert 33 posts 173 karma points
    May 17, 2018 @ 13:49
    Robert
    1

    Unfortunately it's for a webapi and I need to return whats in the db, published or not.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    May 17, 2018 @ 13:53
    Dave Woestenborghs
    0

    Okay keep in mind.

    That this will also return content that is not published yet.

    But I used published content in a web api without problems.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft