title: EF Core HasQueryFilter on Include()
body: <p>I'm a bit confused if the <code>HasQueryFilter</code> method should work on entities that are joined by the <code>Include()</code> method.</p>
  
  <p>From this (old) article, they state the following:
  <a href="https://blogs.msdn.microsoft.com/dotnet/2017/05/12/announcing-ef-core-2-0-preview-1/" rel="nofollow noreferrer">https://blogs.msdn.microsoft.com/dotnet/2017/05/12/announcing-ef-core-2-0-preview-1/</a></p>
  
  <blockquote>
    <p>Filters are applied automatically when queries retrieve data of
    specific types directly as well as through navigation properties, e.g.
    using the <strong>Include()</strong> method.</p>
  </blockquote>
  
  <p>What I have in my <code>DbContext</code> class is the following:</p>
  
  <pre><code>protected override void OnModelCreating(ModelBuilder builder)
  {
      builder.Entity&lt;Post&gt;().HasQueryFilter(x =&gt; x.Removed == null);
  }
  </code></pre>
  
  <p>If I then execute the following, then it also retrieves all the <code>Posts</code> records where <code>Removed</code> is <strong><em>not</em></strong> null.</p>
  
  <pre><code>// Doesn't apply the query filter because of the Include()
  var blog = _dbContext.Blogs.Include(x =&gt; x.Posts).Where(x =&gt; x.Id == 100);
  </code></pre>
  
  <p>If I query <code>Post</code> directly, then the <code>HasQuerFilter</code> does its job.</p>
  
  <pre><code>// Here query filter works, because of query directly on Entity
  var posts = _dbContext.Posts.ToList();
  </code></pre>
  
  <p>So is it correct that this functionality doesn't work (yet?) on entities that are joined using <code>Include()</code>? Or am I mising something?</p>