Copied to clipboard

Flag this post as spam?

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


  • Paul 97 posts 371 karma points
    1 week ago
    Paul
    0

    Linq/Razor Orderby syntax Query

    Hi all,

    I've a query like so:

    var currFolder = Umbraco.TypedMedia(folders);  
    IEnumerable<IPublishedContent> fileList;  
    fileList = currFolder.Children.OrderBy(sortbyoption);
    

    This works, but the call in the OrderBy to a variable is dynamic; which I want to avoid so I was trying....

    var currFolder = Umbraco.TypedMedia(folders);
    IEnumerable<IPublishedContent> fileList;  
    fileList = currFolder.Children.OrderBy(x => x.GetPropertyValue(sortbyoption));
    

    The latter doesn't work. Is there some limitation on OrderBy that prevents me from using strongly typed syntax? I just want to pull in the variable :-S

    Any help appreciated as usual folks!

    EDIT: Umb 7.10.4

  • Paul 97 posts 371 karma points
    1 week ago
    Paul
    0

    Just to add, when sticking break points I can see that .OrderBy(x => x.GetPropertyValue(sortbyoption) brings back the correct information, the Linq statement just seems to ignore it.

  • Paul 97 posts 371 karma points
    1 week ago
    Paul
    0

    No one have any ideas on this one?

  • Alex Skrypnyk 4575 posts 16353 karma points MVP 2x admin
    4 days ago
    Alex Skrypnyk
    0

    Hi Paul

    I think the issue is in a type of property value, please, provide a type of property value, "string" for example:

    fileList = currFolder.Children.OrderBy(x => x.GetPropertyValue<string>(sortbyoption));
    

    GetPropertyValue() - returns an object type, that is hard to compare and sort

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft