Copied to clipboard

Flag this post as spam?

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


  • Drew DeVault 22 posts 43 karma points
    Oct 24, 2011 @ 21:49
    Drew DeVault
    0

    Linq Error on Complex Statement

    Hello,

    I've put together a very complicated linq statement that looks like it works properly to me, but is causing the following error:

    (11): 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

    The goal of this statement is to grab all of the children of forecastNode whose "date" properties are in the future, then order the remaining children by the "date" property and take the first three.

    @forecastNode.Children.Where(x => x.GetProperty("date").Value >= DateTime.Now).OrderBy("date").Take(3)
  • Rodion Novoselov 694 posts 859 karma points
    Oct 25, 2011 @ 00:17
    Rodion Novoselov
    1

    Hi. Generally in most cases you cannot use conventional LINQ with dynamic-related stuff (since lambdas don't support dynamics). However umbraco razor library goes with dynamic linq extensions included and that allows to write linq queries as strings instead of lambda expressions. With Dynamic LINQ your query can be rewriten someway like this:

    @forecastNode.Children.Where("date >= @0", DateTime.Now).OrderBy("date").Take(3)
  • Drew DeVault 22 posts 43 karma points
    Oct 25, 2011 @ 00:19
    Drew DeVault
    0

    Thanks!  I actually got it to work with the Where invocation like so:

    Where("date >= DateTime.Now")
Please Sign in or register to post replies

Write your reply to:

Draft