title: How do I DRY query logic between IEnumerable and IQueryable?
body: <p>Given two entities <code>EntityOne</code> and <code>EntityTwo</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>public class EntityOne
  {
      public string Title { get; set; }
      public bool IsSomething { get; set; }
  }
  </code></pre>
  <pre class="lang-cs prettyprint-override"><code>public class EntityTwo
  {
      ...
  
      public virtual IEnumerable&lt;EntityOne&gt; EntityOnes { get; set; }
  }
  </code></pre>
  <p>and an <code>EntityOneFilter</code> object like:</p>
  <pre class="lang-cs prettyprint-override"><code>public class EntityOneFilter
  {
      public EntityOneFilter(string? query, bool? isSomething, ...)
      {
          ...
      }
      
      public string? Query { get; }
      public bool? IsSomething { get; }
  }
  </code></pre>
  <p>I'd like to reuse the query logic that can be applied to both <code>IEnumerable&lt;EntityOne&gt;</code> and <code>IQueryable&lt;EntityOne&gt;</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>(filter.Query == null || EF.Functions.Like(entity.Title, $&quot;%{filter.Query}%&quot;))
      &amp;&amp; (!filter.IsSomething.HasValue || entity.IsSomething == filter.IsSomething.Value)
      &amp;&amp; ...
  </code></pre>
  <p>So that it can be applied to both <code>IQueryable</code>s coming from a <code>DbContext</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>dbContext.EntityOnes.Where(&lt;something with filter&gt;).FirstAsync();
  </code></pre>
  <p>and also to <code>IEnumerable&lt;EntityOne&gt;</code> that appear as a one to many collection to <code>EntityTwo</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>dbContext.EntityTwos
      .Where(e2 =&gt; e2.EntityOnes.Where(&lt;something with filter&gt;).Any())
      .FirstAsync();
  </code></pre>
  <p>How can I accomplish this?</p>