title: LINQ Between Operator
body: <p>The following works fine with IEnumerable types, but is there any way to get something like this working with IQueryable types against a sql database?</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          var items = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, };
  
          foreach (var item in items.Where(i =&gt; i.Between(2, 6)))
              Console.WriteLine(item);
      }
  }
  
  static class Ext
  {
     public static bool Between&lt;T&gt;(this T source, T low, T high) where T : IComparable
     {
         return source.CompareTo(low) &gt;= 0 &amp;&amp; source.CompareTo(high) &lt;= 0;
     }
  }
  </code></pre>