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.
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.
Get Max Value of a List
Hi guys, I got the following code:
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
Hi Vanilson,
You could do something like this:
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
I don't think you'll need the ToList(). Max() will work with the IEnumerable returned from the Select()
Good point, I was on a little bit of auto pilot while I wrote the statement. Had List's stuck in my head.
Hi Nik, thank you for the reply. I test your solution and it´s giving me the following error in VS:
Best Regards
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.
Hi Nik, It works, thank you...
Best Regards
No problem Vanilson.
is working on a reply...