title: IQueryable<>.ToString() too slow
body: <p>I'm using BatchDelete found on the answer to this question: <a href="https://stackoverflow.com/questions/8538899/ef-code-first-delete-batch-from-iqueryablet">EF Code First Delete Batch From IQueryable&lt;T&gt;?</a></p>
  
  <p>The method seems to be wasting too much time building the delete clause from the IQueryable. Specifically, deleting 20.000 elements using the IQueryable below is taking almost two minutes.</p>
  
  <pre><code>context.DeleteBatch(context.SomeTable.Where(x =&gt; idList.Contains(x.Id)));
  </code></pre>
  
  <p>All the time is spent on this line:</p>
  
  <pre><code>    var sql = clause.ToString();
  </code></pre>
  
  <p>The line is part of this method, available on the original question linked above but pasted here for convenience:</p>
  
  <pre><code>private static string GetClause&lt;T&gt;(DbContext context, IQueryable&lt;T&gt; clause) where T : class
  {
      const string Snippet = "FROM [dbo].[";
  
      var sql = clause.ToString();
      var sqlFirstPart = sql.Substring(sql.IndexOf(Snippet, System.StringComparison.OrdinalIgnoreCase));
  
      sqlFirstPart = sqlFirstPart.Replace("AS [Extent1]", string.Empty);
      sqlFirstPart = sqlFirstPart.Replace("[Extent1].", string.Empty);
  
      return sqlFirstPart;
  }
  </code></pre>
  
  <p>I imagine making <code>context.SomeTable.Where(x =&gt; idList.Contains(x.Id))</code> into a compiled query could help, but AFAIK you can't compile queries while using DbContext on EF 5. In thesis they should be cached but I see no sign of improvement on a second execution of the same BatchDelete.</p>
  
  <p>Is there a way to make this faster? I would like to avoid manually building the SQL delete statement.</p>