title: Entity Framework Share Queries
body: <p>I don't quite know how to word this, so I'm just going to explain my scenario.</p>
  
  <p>I have a scenario where I have a <code>TerminationDate</code> field on an <code>EmploymentHistory</code> table that can be null, or a date in the future.  <code>EmploymentHistory</code> joins to an <code>Employees</code> table and it's a 1:M relationship, where a single <code>Employee</code> can have multiple <code>EmploymentHistory</code> records.  That <code>Employees</code> table joins to a lot of different places such as a <code>Users</code> table that represents the front end portal the <code>Employees</code> can log in to.</p>
  
  <p>I frequently need to grab only the active employees.  The SQL logic for being active is <code>WHERE TerminationDate IS NULL OR TerminationDate &gt;= GETDATE()</code>.  So if TerminationDate is null or if it's set in the future.</p>
  
  <p>So in EF I have these queries like this:</p>
  
  <p><code>// Grab all Active Employees
  context.Employees.Where(e =&gt; e.EmploymentHistory.Any(eh =&gt; eh.TerminationDate == null || eh.TerminationDate &gt;= DateTime.Today).ToList();
  </code></p>
  
  <p><code>// Get all Users 
  context.Users.Where(u =&gt; u.Employee.EmploymentHistory.Any(eh =&gt; eh.TerminationDate == null || eh.TerminationDate &gt;= DateTime.Today).ToList();
  </code></p>
  
  <p>etc</p>
  
  <p>This logic shows up in about 5 different places.  How do I share the <code>EmploymentHistory.Any(eh =&gt; eh.TerminationDate == null || eh.TerminationDate &gt;= DateTime.Today</code> part of the logic when the base nav prop may be different?  Tried playing with <code>Expression&lt;Func&lt;T, bool&gt;&gt;</code> but got no where other than I think I have a solution if I can make all the Entities that need this inherit from a Base and could always assume there's a nav prop called Employee sitting there and the Base is my <code>T</code>.  If I try an extension method, EF Core can only evaluate it client side, not server side. </p>