title: Ef core LazyLoading - Access nested navigation property of type collection threw DetachedLazyLoadingWarning error
body: <p>I tried to access the GradeInfo property of the student's latest grade using ef core 2.1</p>
  
  <p><strong>I listed the models at the end of the question</strong></p>
  
  <pre><code>var students = applicationDbContext.Students.Where(s =&gt; s.Id ==2)
      .Select(student =&gt; new { 
          LatestGrade = student.Grades.OrderBy(g =&gt; g.Date).FirstOrDefault(),
          Id = student.Id
          }).ToList();
  </code></pre>
  
  <p>In addition I use lazy loading proxies (from Microsoft.EntityFrameworkCore.Proxies) in startup.cs</p>
  
  <pre><code>services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; 
      options.UseLazyLoadingProxies()
             .UseSqlServer(connectionString));
  </code></pre>
  
  <p>The error which is thrown is:</p>
  
  <blockquote>
    <p>"Error generated for warning Microsoft.EntityFrameworkCore.Infrastructure.DetachedLazyLoadingWarning: An attempt was made to lazy-load navigation property 'Info' on detached entity of type 'GradeProxy'. Lazy-Loading is not supported for detached entities or entities that are loaded with 'AsNoTracking()'."</p>
  </blockquote>
  
  <p>In addition, i want to state that I tried to add Inculde to the sudents's dbset as described in the following code, but the problem did not resolved.</p>
  
  <pre><code>var student = applicationDbContext.Students.Include( s =&gt; s.Grades )
                  .ThenInclude( grade =&gt; grade.Info).Where(...).Select(...)
  </code></pre>
  
  <hr>
  
  <p><strong><em>models</em></strong></p>
  
  <pre><code>class Student{
     public int Id { get; set;}
     public virtual ICollection&lt;Grade&gt; Grades { get; set;}
  
     ...
  }
  
  class Grade {
     public virtual GrandeInfo Info { get; set;}
     public DateTime Date { get; set;}
  }
  
  class GrandeInfo {
    public int Id { get; set;}
    public int Score { get; set;}
  }
  </code></pre>