Copied to clipboard

Flag this post as spam?

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


  • Pierre Breau 11 posts 121 karma points
    Jul 31, 2019 @ 23:49
    Pierre Breau
    0

    Umbraco TOP 5 Query

    I used the query builder to generate the query for my page and my question is can I do like SQL and select top 5 items from the list in the code below ? or how would I achieve this.

    thanks

    @{ var blogitems = Umbraco.Content(Guid.Parse("SOMEGUID")) .ChildrenOfType("blogItems") .Where(x => x.IsVisible()) .OrderByDescending(x => x.CreateDate); }

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Aug 01, 2019 @ 07:14
    Matthew Wise
    101

    Hi Pierre,

    Before the ; you can add .Take(5) which will take the up to the first 5 items in the list.

    https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.take?view=netframework-4.7.2

    Matt

  • Pierre Breau 11 posts 121 karma points
    Aug 01, 2019 @ 09:30
    Pierre Breau
    0

    Thanks that worked and thanks for the reference link

    cheers

Please Sign in or register to post replies

Write your reply to:

Draft