title: How to obtain ToTraceString for IQueryable.Count
body: <p>I use <code>((ObjectQuery)IQueryable).ToTraceString()</code> to obtain and tweak SQL code that is going to be executed by LINQ.</p>
  
  <p>My problem is that unlike most IQueryable methods IQueryable.Count as defined like this:</p>
  
  <pre><code>    public static int Count(this IQueryable source) {
          return (int)source.Provider.Execute(
              Expression.Call(
                  typeof(Queryable), "Count",
                  new Type[] { source.ElementType }, source.Expression));
      }
  </code></pre>
  
  <p>executes query without compiling and returning IQueryable.
  I wanted to do the trick by something like this:</p>
  
  <pre><code>public static IQueryable CountCompile(this IQueryable source) {
      return source.Provider.CreateQuery(
          Expression.Call(
              typeof(Queryable), "Count",
              new Type[] { source.ElementType }, source.Expression));
  }
  </code></pre>
  
  <p>But then CreateQuery gives me the following exception:</p>
  
  <p><code>LINQ to Entities query expressions can only be constructed from instances that implement the IQueryable interface.</code></p>