0

質問は、以下のタイプのコードに頼らずに、すべての親の子のすべてのエンティティを含む B のリストを返す方法です。単一の linq クエリ内で同じことを達成できるはずだと考えていました。

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);

ありがとう。

4

3 に答える 3

4
List<B> allChildren = x.Parents.SelctMany(p => p.children).ToList()
于 2009-09-15T12:35:42.957 に答える
3
var output = x.Parents.SelectMany(p => p.children).ToList();
于 2009-09-15T12:36:00.337 に答える
1

ネスティングの使用

from parent in x.Parents 
  from child in parent.Children 
  select child;
于 2009-09-15T12:39:13.363 に答える