title: Entity Framework Core - LINQ select over navigational properties creates invalid query
body: <p>Currently, I'm working on an Asp.Net Core website and use Entity Framework Core (currently RC1) for database access with SQL Express LocalDB on the development machine, although MS SQL on the test server gives the same error.</p>
  
  <p>I've run into an issue that when querying multiple levels of navigational properties, invalid SQL would be generated. I created the following test code to reproduce the issue:</p>
  
  <p>4 Classes that represent database tables</p>
  
  <pre><code>public class CarManufacturer
  {
      public Guid Id { get; set; }
      public string Name { get; set; }
      public List&lt;CarModel&gt; CarModels { get; set; }
  }
  
  public class CarModel
  {
      public Guid Id { get; set; }
      public string Name { get; set; }
      public Guid CarManufacturerId { get; set; }
      public CarManufacturer CarManufacturer { get; set; }
      public List&lt;CarTestDriver&gt; CarTestDrivers { get; set; }
  }
  
  public class CarTestDriver
  {
      public Guid Id { get; set; }
      public string Name { get; set; }
      public Guid CarModelId { get; set; }
      public CarModel CarModel { get; set; }
      public List&lt;SpeedingTicket&gt; SpeedingTickets { get; set; }
  }
  
  public class SpeedingTicket
  {
      public Guid Id { get; set; }
      public decimal Amount { get; set; }
      public Guid CarTestDriverId { get; set; }
      public CarTestDriver CarTestDriver { get; set; }
  }
  </code></pre>
  
  <p>DbSets in the Context class</p>
  
  <pre><code>    public DbSet&lt;CarManufacturer&gt; CarManufacturers { get; set; }
      public DbSet&lt;CarModel&gt; CarModels { get; set; }
      public DbSet&lt;CarTestDriver&gt; CarTestDrivers { get; set; }
      public DbSet&lt;SpeedingTicket&gt; SpeedingTickets { get; set; }
  </code></pre>
  
  <p>Now I create a linq query to give me the total amount of tickets sorted by manufacturers</p>
  
  <pre><code>        var ticketCostByManufacturers = Context.CarManufacturers
              .Select(manufacturer =&gt; new
              {
                  manufacturer.Name,
                  TotalTicketAmount = manufacturer.CarModels.SelectMany(model =&gt; model.CarTestDrivers).SelectMany(driver =&gt; driver.SpeedingTickets).Sum(ticket =&gt; ticket.Amount)
              })
              .ToList();
  </code></pre>
  
  <p>Which does two things:</p>
  
  <ol>
  <li>Creates a single query to retrieve all manufacturer Ids and Names</li>
  <li><p>Queries all the tickets with the following, invalid SQL:
  (Only when the first query does yield results)</p>
  
  <pre><code>SELECT [model].[Id],
  [model].[Amount],
  [model].[CarTestDriverId],
  [model].[CarManufacturerId], -- Invalid Column
  [model].[Id],
  [driver].[Id],
  [ticket].[Amount]
  FROM [SpeedingTicket] AS [model]
  CROSS JOIN [CarTestDriver] AS [driver]
  CROSS JOIN [SpeedingTicket] AS [ticket]      
  </code></pre></li>
  </ol>
  
  <p>The query results in an exception due to an invalid column name <code>CarManufacturerId</code> on the table for entity <code>SpeedingTicket</code>, since the query does select <code>[SpeedingTicket] AS [model]</code>. </p>
  
  <p>I've experimented with <code>.Include()</code> as well as with the Fluent API, but both didn't get me to a solution for how to properly use Entity Framework Core here to perform the query.</p>
  
  <p>The exception message itself suggests that my model and the database are out of sync and I should create a new migration, but in fact they are in sync. I guess this suggestion comes from EF assuming a database schema mismatch when a column is not found.</p>
  
  <p>Edit for clarification:</p>
  
  <p>The intention of the question was to find out whether this is an error in my setup (like missing configuration with Fluent API) or if it's still a bug in the current version of Entity Framework Core. @Ivan Stoev did point it it's the latter, a bug in the current code of Entity Framework.</p>