title: SelectMany Three Levels Deep
body: <p>I can flatten the results of a child collection within a collection with SelectMany:</p>
  
  <pre><code> // a list of Foos, a Foo contains a List of Bars
   var source = new List&lt;Foo&gt;() { ... };
  
   var q = source.SelectMany(foo =&gt; foo.Bar)
       .Select(bar =&gt; bar.barId)
   .ToList();
  </code></pre>
  
  <p>this gives me the list of all Bar Ids in the Foo List.  When I attempt to go three levels deep the incorrect result is returned.</p>
  
  <pre><code> var q = source.SelectMany(foo =&gt; foo.Bar)
       .SelectMany(bar =&gt; bar.Widget)
           .Select(widget =&gt; widget.WidgetId)
   .ToList();
  </code></pre>
  
  <p>How should I be using SelectMany to get the list of all Widgets in all Bars in my list of Foos?</p>
  
  <p><strong>Edit</strong>
  I miss-worded the above sentence, but the code reflects the goal.  I am looking for a list of all Widget Ids, not widgets.</p>
  
  <p>An "incorrect" result is not all of the widget ids are returned.</p>