Copied to clipboard

Flag this post as spam?

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

  • David Podmore 15 posts 73 karma points
    May 19, 2015 @ 15:28
    David Podmore

    OrderBy() using lambda?


    Im using a lambda expression to sort a collection of child pages (news articles).

        Layout = "MASTER.cshtml";
        var a = CurrentPage.Children().Where("Visible");
        List<dynamic> b = new List<dynamic>();
        foreach(dynamic item in a) {
        var articles = b.OrderByDescending(x => (x.dateOverride.ToString("yyyy") != "0001" ? x.dateOverride : x.CreateDate ));

    Initially I tried using a.OrderBy(expression) but cannot do so, as a is dynamic (I get the error "Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type").

    Is my above code a correct/efficient way to achieve what I'm after?


  • Mehul Gajjar 48 posts 172 karma points
    May 21, 2015 @ 15:20
    Mehul Gajjar

    Hi David,

    you can also try with IPublishedContent for taking children like below

    IPublishedContent a = CurrentPage.Children().Where("Visible");

    you can alos see below URL for Umbraco Helper

    UmbracoHelper is very useful for such kind of operations.

    Hope it will help you.


    Mehul Gajjar.

Please Sign in or register to post replies

Write your reply to: