title: Linq Group by, Concatenate and load child entities on a list
body: <p>I'm going to simplify a little bit my model in order to show what I want to do. I know perfectly how do that using SQLbut I'm having problems with EF and LINQ.</p>
  
  <p>Sorry for the long post.</p>
  
  <p>I have the next POCO's:</p>
  
  <pre><code>public class Order
  {
     public int Id {get; set;}
     public double Quantity {get; set;}   
     public List&lt;Status&gt; StatusChanges{get; set;}
  }
  public class Status
  {
     public int Id {get; set;}
     public DateTime StatusDate {get; set;}
     public StatusType StatusType  {get; set;}
  }
  public class StatusType 
  {
     public int Id {get; set;}
     public string Code {get; set;}
     public string Description {get; get;}
  }
  </code></pre>
  
  <p>An <code>Order</code> have multiple <code>Status</code> and one <code>Status</code> have only one <code>StatusType</code> </p>
  
  <p>My questions:</p>
  
  <p>1) How to select in a LINQ query a list containg all the orders with the loaded StatusType</p>
  
  <p>I try with </p>
  
  <pre><code>var results= (from o in db.Orders
              select new {o.Id,o.Quantity,o.StatusChanges})
              .Include(o=&gt;o.StatusChanges.Select(s=&gt;s.StatusType));
  </code></pre>
  
  <p>But that's not that I want, I want a list which contains, <code>Order</code>, <code>Status</code> and <code>StatusType</code> (even if the <code>Order</code> info is repetead) I know I can make a double foreach but I would like to know if is a single query way (or a double query one to the db and another using linq to entities)</p>
  
  <p>2) How make a list which contains the <code>Order</code> Id and the Codes of all the status concatenated. Example</p>
  
  <p><strong>Orders:</strong></p>
  
  <pre><code>Id    Quantity
  1       2
  </code></pre>
  
  <p><strong>Status</strong></p>
  
  <pre><code>Id  StatusDate   StatusTypeId
  1    01-10-2014       1
  2    02-10-2014       2
  </code></pre>
  
  <p><strong>StatusType</strong></p>
  
  <pre><code>Id   Code  Description
  1      E    Entered
  2      C    Confirmed
  3      D    Deleted
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <pre><code>OrderId  Quantity    StatusResume
  1         2           E,C
  </code></pre>
  
  <p>I know I can use this <a href="https://stackoverflow.com/questions/614542/use-linq-to-concatenate-multiple-rows-into-single-row-csv-property">question</a> but I don't know how have access to the loaded elements in the list.</p>