title: Web API + ODataQueryOptions + $top or $skip is causing a SqlException
body: <p>This code has been simplified for this example.</p>
  
  <p>The query is actually returned from a service, which is why I would prefer to write the method this way.</p>
  
  <pre class="lang-c# prettyprint-override"><code>[HttpGet]
  public PageResult&lt;ExceptionLog&gt; Logging(ODataQueryOptions&lt;ExceptionLog&gt; options)
  {
      var query = from o in _exceptionLoggingService.entities.ExceptionDatas
                  select new ExceptionLog {
                      ExceptionDataId = o.ExceptionDataId,
                      SiteId = o.SiteId,
                      ExceptionDateTime = o.ExceptionDateTime,
                      StatusCode = o.StatusCode,
                      Url = o.Url,
                      ExceptionType = o.ExceptionType,
                      ExceptionMessage = o.ExceptionMessage,
                      Exception = o.Exception,
                      RequestData = o.RequestData
                  };
  
      var results = options.ApplyTo(query) as IEnumerable&lt;ExceptionLog&gt;;
      var count = results.LongCount();
  
      return new PageResult&lt;ExceptionLog&gt;(results, Request.GetNextPageLink(), count);
  }
  </code></pre>
  
  <p>The above code errors on "results.LongCount()" with the following Exception:</p>
  
  <pre><code>SqlException: The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
  </code></pre>
  
  <p>It appears that I'm getting an exception with when trying to page, like this "$top=2".  Everything works fine if my querystring is like this "$filter=ExceptionDataId gt 100".</p>
  
  <p>Since ExceptionData (the Entity) matches ExceptionLog (business model) I can do something like this as a workaround:</p>
  
  <pre class="lang-c# prettyprint-override"><code>[HttpGet]
  public PageResult&lt;ExceptionLog&gt; Logging(ODataQueryOptions&lt;ExceptionData&gt; options)
  {
      var query = from o in _exceptionLoggingService.entities.ExceptionDatas
                  orderby o.ExceptionDateTime descending
                  select o;
  
      var results = from o in options.ApplyTo(query) as IEnumerable&lt;ExceptionData&gt;
                      select new ExceptionLog {
                          ExceptionDataId = o.ExceptionDataId,
                          SiteId = o.SiteId,
                          ExceptionDateTime = o.ExceptionDateTime,
                          StatusCode = o.StatusCode,
                          Url = o.Url,
                          ExceptionType = o.ExceptionType,
                          ExceptionMessage = o.ExceptionMessage,
                          Exception = o.Exception,
                          RequestData = o.RequestData
                      };
  
      return new PageResult&lt;ExceptionLog&gt;(results, Request.GetNextPageLink(), results.LongCount());
  }
  </code></pre>
  
  <p>But this doesn't completely work for me because it's a little hackish and I can't use the service's method which already gives me an IQueryable.</p>
  
  <p>Another thing to note, is if the Logging method is converted to IQueryable, everything works correctly.  But I need to return the Count with the query so I have to return a PageResult.</p>