title: Eager loading include with using UseLazyLoadingProxies
body: <p>I am creating the db connection like so:</p>
  
  <pre><code>protected override void OnConfiguring(DbContextOptionsBuilder optionbuilder)
  {
      optionbuilder.UseLazyLoadingProxies().UseSqlite(@"Data Source=Data.db");
  }
  </code></pre>
  
  <p>And I am trying to access an object like so:</p>
  
  <pre><code>public static User GetProfile(int uid)
  {
      using (Db db = new Db())
      {
          return db.Users.Include(x =&gt; x.Settings).FirstOrDefault(x =&gt; x.UserId == uid);
      }
  }
  </code></pre>
  
  <p>The user object is as follows:</p>
  
  <pre><code>public class User
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int UserId { get; set; }
  
      public string Name { get; set; }
      public DateTime? LastUsed{ get; set; }
  
      public virtual Setting Settings { get; set; }
  }
  </code></pre>
  
  <p>but upon accessing <code>Users.Settings</code>, it throws the following error:</p>
  
  <blockquote>
    <p>'Error generated for warning
    'Microsoft.EntityFrameworkCore.Infrastructure.LazyLoadOnDisposedContextWarning:
    An attempt was made to lazy-load navigation property 'Settings' on
    entity type 'UserProxy' after the associated DbContext was disposed.'.
    This exception can be suppressed or logged by passing event ID
    'CoreEventId.LazyLoadOnDisposedContextWarning' to the
    'ConfigureWarnings' method in 'DbContext.OnConfiguring' or
    'AddDbContext'.'</p>
  </blockquote>
  
  <p>I understand what this means but it goes against my understanding of includes and how it causes eager loading.</p>
  
  <p>My understanding was that when using an <code>include</code> and accessing the object explicitly by calling <code>FirstOrDefault</code> eager load the related objects to be populated immediately without the need for the db connection to remain open; but apparently, this is not the case. </p>
  
  <p>What would be the right way to do this without requiring the database be left open? </p>