Copied to clipboard

Flag this post as spam?

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


  • patrick 41 posts 93 karma points
    Nov 06, 2012 @ 12:07
    patrick
    0

    How to use Lamda Expression to Select all the names of the children

    Hi I want to retrieve a list with the names of the childpages.

    The childpages need to be joined, so I would have a string like:

    Peter, Patrick, Denise

    var instructors = Library.Join(",",school.Descendants("InstructorPage").Where("Visible").Select("Name").ToArray());

    I have something like the above but this won't work.

    Is there a short way of doing this, or do I need to make a foreach loop for this?

    Thanks,

    Patrick

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 06, 2012 @ 12:54
    Dirk De Grave
    0

    i'd say that your Select("Name") isn't working... How about:

    var instructors = Library.Join(",", school.Descendants("InstructorPage").Where("Visible").Items.Select(d => d.Name).ToArray());

    Cheers,

    /Dirk

     

  • patrick 41 posts 93 karma points
    Nov 06, 2012 @ 13:45
    patrick
    0

    Hi Dirk,


    Thanks, for the response.

    I tried that before, but that will throw an exception:

    Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

     

  • patrick 41 posts 93 karma points
    Nov 06, 2012 @ 14:50
    patrick
    0

    For now I used a different approach:

    var names = new List<string>();
    foreach (var instructor in school.Descendants("InstructorPage").Where("Visible"))
    {
          names.Add(instructor.Name);
    }

    @String.Join(", ",names.ToArray())      

    Don't like the solution, so I'll look into this later.
                                
                                  

Please Sign in or register to post replies

Write your reply to:

Draft