I managed to count unique values by using .Items, which you can then do a Distinct() on. Here's an example that finds unique years from a datepicker property:
var uniqueYears = myList.Items.Select(x => umbraco.library.FormatDateTime(x.GetPropertyValue("myDateProperty"), "yyyy")).Distinct().OrderByDescending(z => z);
Not sure how to do your second request, but maybe this will help get you started :)
Trying to stand on the shoulders of Giants here but toppling over:
var nodes = Model.NodeById(1087); var uniqueYears = nodes.Children.Select(x => umbraco.library.FormatDateTime(x.GetPropertyValue("DatePublished"), "yyyy")).Distinct().OrderByDescending(z => z);
which gives me the following nonsensical error (alas I know not what the flip lambda is or what a delegate or expression tree type is)
error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Would probably prefer to use one of the solutions above but not sure where I'm going wrong. perhaps I'm missing a @using declaration or something silly like that.
Find and count unique values in a dynamicNodeList
I have a dynamicNodeList with a set of values.
First of all I would like to count unique values
Secondly I would like to create a new list of with unique values and their number of occurences in the original list.
Count() doesn't seem to apply for Dynamic Node Lists, and neither does Distinct()
Hi,
I managed to count unique values by using .Items, which you can then do a Distinct() on. Here's an example that finds unique years from a datepicker property:
Not sure how to do your second request, but maybe this will help get you started :)
-Tom
Thanks - that did the trick for the first problem :o)
Just what I was looking for, thanks Tom!
Trying to stand on the shoulders of Giants here but toppling over:
which gives me the following nonsensical error (alas I know not what the flip lambda is or what a delegate or expression tree type is)
error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
am using Umbraco 4.8 if that helps
The Select method doesn't exist on a DynamicNodeList. I don't have any way of testing it at the moment, but try something like the following:
If that doesn't work, something like this might:
Hi Douglas,
thanks a lot for your reply...
of the two examples given both give me the same lambda error as above.
I ended up finding this thread which did the trick for me (@alex's answer)
http://our.umbraco.org/forum/developers/razor/19020-Is-there-something-like-%27GroupBy%27
Would probably prefer to use one of the solutions above but not sure where I'm going wrong. perhaps I'm missing a @using declaration or something silly like that.
- Tim
is working on a reply...