tags:

views:

114

answers:

3

Question is How do a return a List of B with all the entities in children of all Parents without resorting to the type of code below, I was thinking u must be able to acheive the same within a single linq query?

Class Parent {
    public Title,
    public children List<B>,
}

data = List<A>

var childLists = from x in x.Parents select x.children;             
List<B> output = new List<B>();

foreach (List<B> b in childLists)
    output.AddRange(b);

Thanks.

+4  A: 
List<B> allChildren = x.Parents.SelctMany(p => p.children).ToList()
Lee
+3  A: 
var output = x.Parents.SelectMany(p => p.children).ToList();
LukeH
A: 

using nesting

from parent in x.Parents 
  from child in parent.Children 
  select child;
Shay Erlichmen
To be clear, i'd wrap the nested querys in parens.
RCIX