title: Flatten list with EF SelectMany
body: <p>I want to go ahead and get all or at least some of the columns from my Projects table which has a one to many relationship with my TimeTrackings table.</p>
  
  <p>When I create the query, only all the child (TimeTracking entity) fields come out and just the ID of the parent (Project table).</p>
  
  <p>How can I achieve an effective join using the SelectMany to flatten a list getting all the columns or at least specifying specific columns from each of the two entities.</p>
  
  <p>Below, is the EF query I'm using:</p>
  
  <pre><code>Customers.SelectMany(p =&gt; p.Projects).Where (p =&gt; p.Quote != null).SelectMany (t =&gt; t.TimeTrackings).Where (t =&gt; t.Notes != null)
  </code></pre>
  
  <p>Below is the generated SQL query via LINQPad. <strong>Notice how only the ProjectID and not the rest of the associated columns for that entity come out.</strong></p>
  
  <pre><code>SELECT 
      [Extent2].[TimeTrackingID] AS [TimeTrackingID], 
      [Extent2].[ProjectID] AS [ProjectID], 
      [Extent2].[StartDate] AS [StartDate], 
      [Extent2].[EndDate] AS [EndDate], 
      [Extent2].[Notes] AS [Notes], 
      [Extent2].[CreatedDate] AS [CreatedDate], 
      [Extent2].[UpdatedDate] AS [UpdatedDate]
      FROM  [dbo].[Projects] AS [Extent1]
      INNER JOIN [dbo].[TimeTrackings] AS [Extent2] ON [Extent1].[ProjectID] = [Extent2].[ProjectID]
      WHERE ([Extent1].[Quote] IS NOT NULL) AND ([Extent2].[Notes] IS NOT NULL)
  </code></pre>
  
  <p>Below, is the output of the query:
  <img src="https://i.stack.imgur.com/qDZup.png" alt="enter image description here"></p>