title: How can i convert a DBQuery<T> to an ObjectQuery<T>?
body: <p>I've got a <code>DBQuery&lt;T&gt;</code> which converts to an <code>IQueryable&lt;T&gt;</code> (this bit works fine). But then I'm trying to convert the IQueryable to an ObjectQuery .. which fails :-</p>
  
  <pre><code>public void Foo(this IQueryable&lt;T&gt; source)
  {
      // ... snip ...
  
      ObjectQuery&lt;T&gt; objectQuery = source as ObjectQuery&lt;T&gt;;
      if (objectQuery != null)
      {
          // ... do stuff ...
      }
  }
  </code></pre>
  
  <p>This used to work before I changed over to Entity-Framework 4 CTP5 <em>Magic Unicorn blah blah blah</em>. Now, it's not working - ie. <code>objectQuery</code> is <code>null</code>.</p>
  
  <p>Now, <code>DBQuery&lt;T&gt; inherits IQueryable&lt;T&gt;</code> .. so I thought this should work.</p>
  
  <p>If i change the code to ..</p>
  
  <pre><code>var x = (ObjectQuery&lt;T&gt;) source;
  </code></pre>
  
  <p>then the following exception is thrown :-</p>
  
  <blockquote>
    <p>System.InvalidCastException: Unable to
    cast object of type
    'System.Data.Entity.Infrastructure.DbQuery<code>1[Tests.Models.Order]'
    to type
    'System.Data.Objects.ObjectQuery</code>1[Tests.Models.Order]'.</p>
  </blockquote>
  
  <p>Any suggestions?</p>