Copied to clipboard

Flag this post as spam?

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


  • Robert 30 posts 149 karma points
    5 days ago
    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 1268 posts 4651 karma points MVP c-trib
    5 days ago
    Dan Diplo
    0

    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 2687 posts 8070 karma points MVP 2x admin c-trib
    5 days ago
    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 30 posts 149 karma points
    5 days ago
    Robert
    0

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

  • Dave Woestenborghs 2687 posts 8070 karma points MVP 2x admin c-trib
    5 days ago
    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