title: Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
body: <p>I need to create a Global Query Filter that filters only those Users who belong belong to a certain Tenant.</p>
  
  <p>However, I get a stackoverflow when adding the queryfilter to OnModelCreating.</p>
  
  <p>I get the TenantId from the current logged in user, using IHttpContextAccessor. This works quite fine with other Entities, but ApplicationUser creates the error. Is this perhaps a problem of circular code?</p>
  
  <p>My ApplicationDbContext is as follows (abbreviated for clarity purposes)</p>
  
  <pre><code>public class ApplicationDbContext
  : IdentityDbContext&lt;ApplicationUser, ApplicationRole, string, IdentityUserClaim&lt;string&gt;,
  ApplicationUserRole, IdentityUserLogin&lt;string&gt;,
  IdentityRoleClaim&lt;string&gt;, IdentityUserToken&lt;string&gt;&gt;
  {        
      private readonly IHttpContextAccessor _contextAccessor;
  
      public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options, IHttpContextAccessor contextAccessor)
          : base(options)
      {
          _contextAccessor = contextAccessor;
      }
  
      public virtual Guid? CurrentTenantId
      {
          get
          {
              return Users.FirstOrDefault(u =&gt; u.UserName == _contextAccessor.HttpContext.User.Identity.Name)?.TenantId;
          }
      }
  
      public virtual string CurrentUserName
      {
          get
          {
              return Users.FirstOrDefault(u =&gt; u.UserName == _contextAccessor.HttpContext.User.Identity.Name)?.UserName;
          }
      }
  
      public DbSet&lt;ApplicationUser&gt; ApplicationUser { get; set; }
      public DbSet&lt;Tenant&gt; Tenant { get; set; }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
  
          builder.Entity&lt;Tenant&gt;().HasQueryFilter(e =&gt; e.TenantId == CurrentTenantId);
          builder.Entity&lt;ApplicationUser&gt;().HasQueryFilter(e =&gt; e.TenantId == CurrentTenantId);            
      }       
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have added <code>services.AddHttpContextAccessor()</code> to the ConfifureServices section in my startup.</p>
  
  <p>Any suggestions on how to resolve this?</p>