Copied to clipboard

Flag this post as spam?

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


  • Vanilson 28 posts 150 karma points
    Jul 18, 2016 @ 11:29
    Vanilson
    0

    Hi guys, I got the following code:

    var total = Umbraco.Content(34839).Children.Where("Visible").ToList();
    

    My Children content have a field called value, I want to get all the values and then get max value. I know that using List

    Best Regards

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jul 18, 2016 @ 11:34
    Nik
    0

    Hi Vanilson,

    You could do something like this:

    var total = Umbraco.Content(34839).Children.Where("Visible").ToList().Select(c=> c.GetPropertyValue<int>("value")).ToList().Max();
    

    Basically, that (may not be 100% accurate and need a bit of tweaking), should select a list of your property "value" with the contents converted to an int. It should then find the max in that list.

    Nik

  • David Peck 687 posts 1863 karma points c-trib
    Jul 18, 2016 @ 11:45
    David Peck
    1

    I don't think you'll need the ToList(). Max() will work with the IEnumerable returned from the Select()

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jul 18, 2016 @ 13:41
    Nik
    0

    Good point, I was on a little bit of auto pilot while I wrote the statement. Had List's stuck in my head.

  • Vanilson 28 posts 150 karma points
    Jul 18, 2016 @ 12:09
    Vanilson
    0

    Hi Nik, thank you for the reply. I test your solution and it´s giving me the following error in VS:

    enter image description here

    Best Regards

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jul 18, 2016 @ 13:41
    Nik
    100

    Hi Vanilson,

    Try changing from Umbraco.Content to Umbraco.TypedContent. Umbraco.Content starts the whole lot working on dynamic content where as Umbraco.TypedContent will start the process using IPublishedContent.

  • Vanilson 28 posts 150 karma points
    Jul 20, 2016 @ 11:21
    Vanilson
    0

    Hi Nik, It works, thank you...

    Best Regards

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jul 20, 2016 @ 14:00
    Nik
    0

    No problem Vanilson.

Please Sign in or register to post replies

Write your reply to:

Draft