Copied to clipboard

Flag this post as spam?

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


  • Vanilson 28 posts 150 karma points
    Aug 04, 2016 @ 21:50
    Vanilson
    0

    Hi guys I´m trying to execute the following query.

    var umbHelper = new UmbracoHelper(UmbracoContext.Current);
    IPublishedContent query= umbHelper.TypedContent(34924).Children.Where(x=>x.system=="north");
    

    But it´s returning me the following error:

    “Delegate 'System.Func

    Does anyone knows how to solve this problem?

    Best Regards

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Aug 04, 2016 @ 22:26
    Nicholas Westby
    0

    What version of Umbraco are you using?

    What happens when you "go to definition" on the "Where" function (a screenshot would be useful)?

    What happens when you change your code to this:

    var umbHelper = new UmbracoHelper(UmbracoContext.Current);
    var query= umbHelper.TypedContent(34924).Children.Where(x => x.system=="north");
    

    Where is this code running from (e.g., action method in controller, CSHTML file)?

    What happens if you add using System.Linq at the top of your file?

  • Vanilson 28 posts 150 karma points
    Aug 05, 2016 @ 05:18
    Vanilson
    0

    Hi Nicholas thank you for your reply.

    I´m using Umbraco 7.2.1.

    Go to definition on the where

    enter image description here

    When I change my code to:

    var query= umbHelper.TypedContent(34924).Children.Where(x => x.system=="north");
    

    Gives me the same error.

    Where is this code running from (e.g., action method in controller, CSHTML file)? I´m running my using action method in controller What happens if you add using System.Linq at the top of your file?

    I already imported System.Linq

    Best Regards

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Aug 05, 2016 @ 06:18
    Nicholas Westby
    0

    It seems strange to me that you are able to type x.system=="north", as I don't believe "system" is a property on IPublishedContent. It's almost like that's using the dynamic syntax or something. What happens when you try this:

    var query = umbHelper.TypedContent(34924).Children.ToList().Where(x => true == true);
    

    You might also try:

    var query = umbHelper.TypedContent(34924).Children().ToList().Where(x => true == true);
    

    You can also run the Where extension method directly as a static function call, but I'm not sure of the exact code (I don't have an IDE open at the moment). I imagine it would look something like this:

    var query = System.Linq.CollectionExtensions.Where(umbHelper.TypedContent(34924).Children.ToList(), x => true == true);
    

    By calling it directly rather than relying on the extension method syntax, you can be sure you are calling the correct function.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Aug 05, 2016 @ 06:25
    Dave Woestenborghs
    1

    Hi Vanilson,

    Are you trying to use the models builder to have strongly typed models ?

    If not can you try to this line of code ? Because I'm suspecting you are mixing strongly typed and dymanic query syntax. And that doesn't work

    var query= umbHelper.TypedContent(34924).Children.Where(x => x.GetPropertyValue<string>("system")=="north");
    

    To have understanding about the difference between strongly typed and dynamic syntax read this article I wrote for the Umbraco Calendar :

    http://24days.in/umbraco/2015/strongly-typed-vs-dynamic-content-access/

    My advice by the way is to always use the strongly typed IPublishedContent or to use the models builder to generate models from doctypes for you.

    Dave

  • Vanilson 28 posts 150 karma points
    Aug 05, 2016 @ 15:36
    Vanilson
    0

    @Nicholas

    I made a mistake in the expression, "system" is a property in my document type, above is the query that I´m trying to execute:

    var  query = umbHelper.TypedContent(34924).Children.Where(x => x.GetPropertyValue<string>("system") == "north");
    

    @Dave

    I execute the query in my controller and it doesn´t return any result.

    I have the following structure of contents:

    enter image description here

    I want to return all the items inside the sub-contents by comparing if the contents are in Content 1 or Content 2 and I´m having problems to do this.

    Best Regards

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Aug 05, 2016 @ 16:31
    Nicholas Westby
    100

    What does this list contain when you run it?

    var systemValues = umbHelper.TypedContent(34924).Children.Select(x => x.GetPropertyValue<string>("system")).ToList();
    

    My best guess is it will contain an item that says "North" (i.e., the first letter being uppercase). Not really sure what your data looks like though, so I could be wrong. If I am correct by chance, you could probably get it working like this:

    var query = umbHelper.TypedContent(34924).Children.Where(x => "North".InvariantEquals(x.GetPropertyValue<string>("system")));
    
  • Vanilson 28 posts 150 karma points
    Aug 22, 2016 @ 11:46
    Vanilson
    0

    Hi guys, sorry for answering too late. Nicholas it works, but I got one question, why I got to put the North letter in Uppercase?

    Best Regards

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Aug 22, 2016 @ 14:10
    Nicholas Westby
    0

    It doesn't have to be uppercase, that's just how I happened to write it. The InvariantEquals function does a case-insensitive comparison (i.e., it ignores uppercase and lowercase).

Please Sign in or register to post replies

Write your reply to:

Draft