Copied to clipboard

Flag this post as spam?

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


  • jaygreasley 416 posts 403 karma points
    Oct 03, 2013 @ 18:51
    jaygreasley
    0

    Error when running lambda query in Razor

    Hi all,

    I have a docType Actor that has a property alias of age.

    I have this query in my view:

    var childrenGreaterThanTen = Model.Content.Children.Where(x => x.GetProperty("age").Value > 10 );

    But I get an error:

    Compiler Error Message: CS1593: Delegate 'System.Func<Umbraco.Core.Models.IPublishedContent,int,bool>' does not take 1 arguments

    Am I missing something simple?

    TIA

    Jay

     

  • jaygreasley 416 posts 403 karma points
    Oct 03, 2013 @ 18:53
    jaygreasley
    0

    aha, for anyone else hitting this, I had to cast the property to an int:

     var childrenGreaterThanTen = Model.Content.Children.Where(x => x.GetPropertyValue<int>("age") > 10 );

  • Charles Afford 1163 posts 1709 karma points
    Oct 06, 2013 @ 23:08
    Charles Afford
    0

    Yea its because GetPropertyValue returns a string

    Be carefull here  you have no checking to make sure its an int.

    int childrenGreaterThanTen = Model.Content.Children.Where(x => x.GetPropertyValue("age") > 10 );

    do

    int childrenGreaterThanTen = 0;

    Int32.TryParse(Model.Content.Children.Where(x => x.GetPropertyValue("age") > 10 ) out childrenGreaterThanTen )

    this way you can ensure you get an int and nothing will throw if you get a diffrent type :).  Charlie

Please Sign in or register to post replies

Write your reply to:

Draft