Copied to clipboard

Flag this post as spam?

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


  • Nicolai 48 posts 201 karma points
    Aug 24, 2016 @ 20:03
    Nicolai
    0

    WHERE operation with a DynamicNodeList

    I got this problem where I want to do this:

    filtered = yearFolder.Children.Where(x=> (x.placement.First().Id) ==  source);
    

    But yearFolder is dynamic and therefore I get the following 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"

    Full Code is below:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using System.Globalization;
    @{ 
        int source = Convert.ToInt32(@Parameter.source); 
    
        dynamic yearFolders = Model.NodeById(6207).Children.Where("NodeTypeAlias == \"IndholdMappeYear\"").OrderBy("createDate").Take(2);
    
        string caption = "";
    
        foreach (var yearFolder in yearFolders) {
    
            dynamic filtered;
    
            if (source == 0) {
                filtered = yearFolder;
            }else {
                filtered = yearFolder.Children.Where(x=> (x.placement.First().Id) ==  source);
            }
    
            foreach (var debat in filtered.Children) {      
    
            }
        }
    }
    

    Does anyone know a work-around ?

    Im using Umbraco 4.11.10

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Aug 31, 2016 @ 10:18
    Alex Skrypnyk
    0

    Hi Nicolai,

    It's right and this is the big disadvantage of using dynamic types, you can't use LINQ and debug errors, also you haven't IntelliSense in the visual studio.

    Can you rewrite this code to strongly typed?

    Thanks,

    Alex

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Sep 08, 2016 @ 16:10
    Alex Skrypnyk
    0

    Hi Nicolai,

    Did you solve your problem?

    Thanks

  • Nicolai 48 posts 201 karma points
    Sep 08, 2016 @ 17:30
    Nicolai
    0

    Not for this specific solution. But I just added another macro and script when i wanted the filtered search. To bad there was no "fast" solution for this. Thanks for trying tho!

    -Nicolai

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Sep 09, 2016 @ 08:08
    Alex Skrypnyk
    0

    You are welcome, Nicolai.

    Just if you need some great advice - post your code here.

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft