Copied to clipboard

Flag this post as spam?

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


  • Alessandro 21 posts 51 karma points
    May 02, 2014 @ 11:58
    Alessandro
    0

    Umbraco 6.2 and lambda expression

    Hi

    after upgraded to 6.2 version, my code doesn't work anymore.

    The problem is with this where condition:

    DynamicPublishedContent node = Umbraco.Content(1212);
    DynamicPublishedContent nodeT = node.Children.Where(x => x.DocumentTypeAlias == "Indice").FirstOrDefault() as DynamicPublishedContent;
    

    Cannot convert lambda expression to type 'string' because it is not a delegate type

    if i try to change this code into this:

    DynamicPublishedContent node = Umbraco.Content(1212);
    var nodeT = node.Children.Where("DocumentTypeAlias == Indice");
    

    the error became:

    Can only unbox from an object or interface type to a value type.

    any suggestion?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 02, 2014 @ 14:32
    Jeavon Leopold
    0

    Hi Alessandro,

    You have a mixture of Typed and Dynamic Models, could you try these:

    Typed:

    var node = Umbraco.TypedContent(1212);
    var nodeT = node.Children.Where(x => x.DocumentTypeAlias == "Indice").FirstOrDefault();
    

    Dynamic:

    var node = Umbraco.Content(1212);
    var nodeT = node.Children.Where("DocumentTypeAlias == @0","Indice").FirstOrDefault();
    

    And see if either work?

    Jeavon

  • Alessandro 21 posts 51 karma points
    May 02, 2014 @ 14:53
    Alessandro
    0

    The second method works...

    thanks

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 02, 2014 @ 14:59
    Jeavon Leopold
    0

    Cool, first one doesn't?

  • Alessandro 21 posts 51 karma points
    May 02, 2014 @ 15:02
    Alessandro
    0

    The first one too. why the old code works with version previous to 6.2?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 02, 2014 @ 15:10
    Jeavon Leopold
    0

    Great, Im not sure exactly but you can't use a lamda expression with dynamics so it's strange that it worked previously.

    A lot has been changed to IPublishedContent between v6.1.6 and v6.2.0 so something must have been "corrected".

    Was your code in v6.1.6 exactly the same as this?

  • Alessandro 21 posts 51 karma points
    May 02, 2014 @ 15:18
    Alessandro
    0

    The old code

    DynamicPublishedContent node = Umbraco.Content(1212);
    DynamicPublishedContent nodeT = node.Children.Where(x => x.DocumentTypeAlias == "Indice").FirstOrDefault() as DynamicPublishedContent;
    

    works like a charm with version 6.1.6.

    Can you point me to the docs with the changes to IPublishedContent between v6.1.6 and v6.2.0 so i can refactor my other code?

    thanks

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 02, 2014 @ 15:30
    Jeavon Leopold
    0

    Yes, I have just tested to confirm myself. All changes in v6.2 are listed here, however I think this is possibly a unintended breaking change as the result of something else being changed.

    You should raise a issue here and assign to Stephan

Please Sign in or register to post replies

Write your reply to:

Draft