Copied to clipboard

Flag this post as spam?

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


  • Fengelz 106 posts 221 karma points
    Jan 27, 2010 @ 12:04
    Fengelz
    0

    Use Linq on Node

    I'm pretty new to link but just used it on a Media iteration with success.

    I have to iterate through som children of a node but I cant seem to use the lambda expression on the Node.Children object which is an object of type "Nodes".

    Is there anyway I can convert the Node.Children so I can use lambda expressions on it or should I go another way (ie xslt).

    Heres an example of what im trying to do, which fails: 

    var voteNodes = 

                from vote new Node(Helper.VotesNodeId).Children

                where vote.getProperty("Uploader").Value.ToString() == memberId.ToString() 

                select vote;

    best regards Sune Fengel

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jan 27, 2010 @ 13:59
    Thomas Höhler
    0

    The nodes.children are normal arrays of <Node> so you can't use LinQ. You can add the children into a List<Node> where you can use LinQ on:

    List<Node> children = new List<Node>();
    children.AddRange(new Node(Helper.VotesNodeId).Children);
    var voteNodes = from vote new Node(Helper.VotesNodeId).Children
    where vote.getProperty("Uploader").Value.ToString() == memberId.ToString()
    select vote;

    hth, Thomas

  • Fengelz 106 posts 221 karma points
    Jan 27, 2010 @ 16:23
    Fengelz
    2

    I just realised that I cant AddRange directly because Children is a Nodes class which inherits Collectionbase so I enden up doing this:

     

     List<Node> children = new Node(Helper.VotesNodeId).Children.Cast<Node>().ToList();
            var voteNodes = 
                from vote in children 
            where vote.GetProperty("Uploader").Value.ToString() ==  memberId.ToString() 
                select vote;

     

    I Havent tested it yet but it compiles, so it probably works :).

    - Sune

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies