Copied to clipboard

Flag this post as spam?

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


  • Fredrik Esseen 610 posts 906 karma points
    Dec 22, 2020 @ 09:56
    Fredrik Esseen
    0

    Not able to group by year

    In Umbraco 7 i did the following:

    var items = selection.Descendants().Where("Visible").OrderBy("datum desc").GroupBy("datum.Year");
    

    Im trying to achieve the same thing in Umbraco 8 but it only renders one group:

    var items = selection.Descendants().Where(x => x.IsVisible() ).OrderByDescending(x => x.Value<DateTime>("datum")).GroupBy(x => x.Value<DateTime>("datum.Year"));
    

    Is it not possible to use the same way with "datum.year"?

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Dec 22, 2020 @ 10:06
    Matthew Wise
    100

    Hi Fredik,

    I believe you want

    .GroupBy(x =>x.Value<DateTime>("datum").Year)
    

    Hope this helps

    Matt :)

  • Fredrik Esseen 610 posts 906 karma points
    Dec 22, 2020 @ 10:08
    Fredrik Esseen
    0

    That worked! So simple :). Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft