title: How can I automatically filter out soft deleted entities with Entity Framework?
body: <p>I am using Entity Framework Code First. I override <code>SaveChanges</code> in <code>DbContext</code> to allow me to do a "soft delete":</p>
  
  <pre><code>if (item.State == EntityState.Deleted &amp;&amp; typeof(ISoftDelete).IsAssignableFrom(type))
  {
      item.State = EntityState.Modified;
      item.Entity.GetType().GetMethod("Delete")
          .Invoke(item.Entity, null);
  
      continue;
  }
  </code></pre>
  
  <p>Which is great, so the object knows how to mark itself as a soft delete (In this case it just sets <code>IsDeleted</code> to <code>true</code>).</p>
  
  <p>My question is how can I make it such that when I retrieve the object it ignores any with <code>IsDeleted</code>? So if I said <code>_db.Users.FirstOrDefault(UserId == id)</code> if that user had <code>IsDeleted == true</code> it would ignore it.  Essentially I want to filter? </p>
  
  <p>Note: I do not want to just put <code>&amp;&amp; IsDeleted == true</code> 
  That's why I am marking the classes with an interface so the remove knows how to "Just Work" and I'd like to somehow modify the retrieval to know how to "Just Work" also based on that interface being present.</p>