title: Pivot data in two nested List<T> with Linq
body: <p>I have the following class structure:</p>
  
  <pre><code>class Employee()
  {
    public String Name { get; set; }
    public List&lt;WorkDay&gt; WorkDays { get; set; }
  }
  
  class WorkDay()
  {
    public DateTime Date { get; set; }
    public Int Hours { get; set; }
  }
  </code></pre>
  
  <p>Is it possible to pivot the <code>List&lt;Employee&gt;</code> with Linq so i have result like this in my DataGridView:</p>
  
  <pre><code>           | Name    | Name    |...| Name      |
  Date       | Hours   | Hours   |   | Hours     |
  Date       | Hours   | Hours   |   | Hours     |   
  Date       | Hours   | Hours   |   | Hours     |
  Date       | Hours   | Hours   |   | Hours     |
  ...        | Hours   | Hours   |   | Hours     |
  </code></pre>
  
  <p>It's tricky because it's two nested lists and i only found examples with single list which are pretty straightforward.
  <a href="https://stackoverflow.com/questions/167304/is-it-possible-to-pivot-data-using-linq">Is it possible to Pivot data using LINQ?</a></p>
  
  <p>I got to this point but it's not quite there yet:</p>
  
  <pre><code>var _result = Employees.SelectMany(x =&gt; x.WorkDays)
                         .GroupBy(x =&gt; x.Date)
                         .Select(y =&gt; new
                                      {
                                          DATE = y.Key,
                                          NAME = y.Select(z =&gt; z.Employee.Name).ToArray()
                                      })
                         .ToList();
  </code></pre>
  
  <p>I would appreciate any suggestions.</p>