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) {
b.Add(item);
}
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?
OrderBy() using lambda?
Hi,
Im using a lambda expression to sort a collection of child pages (news articles).
Initially I tried using
a.OrderBy(expression)
but cannot do so, asa
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?
Thanks.
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
https://github.com/umbraco/Umbraco4Docs/blob/master/Documentation/Reference/Querying/UmbracoHelper/index.md
UmbracoHelper is very useful for such kind of operations.
Hope it will help you.
Regards,
Mehul Gajjar.
is working on a reply...