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()
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;
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 :).
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
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:
hth, Thomas
I just realised that I cant AddRange directly because Children is a Nodes class which inherits Collectionbase so I enden up doing this:
I Havent tested it yet but it compiles, so it probably works :).
- Sune
is working on a reply...
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.