title: Entity Framework Core: Global query filter not filtering correctly after data change
body: <p>We implemented a soft deletion pattern with Entity Framework Core, very similar to <a href="https://www.meziantou.net/2017/07/10/entity-framework-core-soft-delete-using-query-filters" rel="nofollow noreferrer">this solution</a>, but with a nullable column "DeleteDate" instead of an IsDeleted flag. If the date is filled, the row is considered deleted and filtered out:</p>
  
  <pre><code>modelBuilder.Entity&lt;TEntity&gt;().HasQueryFilter(e =&gt; !EF.Property&lt;DateTime?&gt;(e, "SysDeletedOn").HasValue);
  </code></pre>
  
  <p>The following code bit would update one item while doing so, delete one of its child elements, but in the returned item, the deleted child would still be contained. Only a new query of all items would filter the children collection correctly.</p>
  
  <pre><code>public async Task&lt;Item&gt; UpdateItemAsync(ItemDto itemDto)
  {
      var itemEntity = await _context.Items.SingleOrDefaultAsync(i =&gt; i.Id == itemDto.Id);
  
      if(itemEntity != null)
      {
          return;
      }
  
      // Update item's properties here
      // ...
  
      foreach (var child in itemDto.Children)
      {
          // Update child here
          // ...
      }
  
      foreach (var child in itemDto.RemovedChildren)
      {
          var childEntity = await itemEntity.SingleOrDefaultAsync(i =&gt; i.Id == child.Id);
          _context.Remove(childEntity);
      }
  
      await _context.SaveChangesAsync();
  
      // Read and return updated item
      return await _context.Items.SingleOrDefaultAsync(i =&gt; i.Id == itemDto.Id);
  }
  </code></pre>
  
  <p>The question is now: How can I get the correct list in this method after this change (deletion) has been made? Do I have to clear the cache somehow between <code>SaveChangesAsync</code> and reading the context again?</p>
  
  <p>The regular updates (property values) of the item are returned correctly. Also,  it works when I query the items with <code>.AsNoTracking()</code> which also turns off caching, obviously.</p>