title: IQueryProvider override
body: <p>I'm trying to hook some business logic onto EntityFramework v4, and the best place I can do this is just before a query is run.</p>
  
  <p>I was hoping I would be able to override the default IQueryProvider, simply adding a method hook into Execute(Expression expr):</p>
  
  <pre><code>    public TResult Execute&lt;TResult&gt;(Expression expression)
      {
          // Do stuff here.
          return this.BaseProvider.Execute&lt;TResult&gt;(expression);
      }
  </code></pre>
  
  <p>However, I'm having difficulty getting the IQueryable to use my IQueryProvider (the ObjectQuery object has a Provider{} attribute, but it's get; only and returns a pre-defined class instance).
  Is there any way to use your own custom IQueryProvider in this manner without writing an entire new query stack (ObjectSet, ObjectContext etc.)?</p>
  
  <p>EDIT</p>
  
  <p>Sorry: I'm not talking about adding any new classes if possible EXCEPT the one that implements IQueryProvider. A wrapper is fine in principal but as I have no intention of implementing IObjectSet or subclassing ObjectQuery&lt;T&gt; the wrapper will only be used on the first pass through CreateQuery:</p>
  
  <pre><code>    public IQueryable&lt;TElement&gt; CreateQuery&lt;TElement&gt;(Expression expression)
      {
          return this.BaseProvider.CreateQuery&lt;TElement&gt;(expression);
      }
  </code></pre>
  
  <p>After this point, as I am using the standard ObjectSet inside the wrapper the IQueryProvider will revert to the pre-defined one and my IQueryProvider will not catch any futher calls.</p>
  
  <p>So: Is there a way to implement and use IQueryProvider WITHOUT trying to add a wrapper, which forces me to use a full custom stack of IQueryxxx objects?</p>