title: Unable to cast object of type 'System.Linq.EnumerableQuery`1[Entities.Test]' to type 'System.Data.Objects.ObjectQuery`1[Entities.Test]'
body: <p>I'm using Entity Framework 4.2 (EntityFramework.dll v4.0.30319) Code First and have a LINQ query which can be simplified to:</p>
  
  <pre><code>IQueryable&lt;Test&gt; testQuery = from test in repository.Tests select test;
  </code></pre>
  
  <p>The <code>repository.Tests</code> is <code>IQueryable&lt;Test&gt;</code> implemented directly as <code>DbSet&lt;Test&gt;</code> in Enity Framework's <code>DbContext</code>.</p>
  
  <p>I noticed that my queries are somehow case-sensitive with case-insensitive collation in Microsoft SQL Server Database. Suspicious, so I wanted to trace the SQL. But when I do this:</p>
  
  <pre><code>var trace = ((ObjectQuery&lt;Test&gt;)testQuery).ToTraceString();
  </code></pre>
  
  <p>I get exception:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Linq.EnumerableQuery<code>1[Entities.Test]' to type 'System.Data.Objects.ObjectQuery</code>1[Entities.Test]'.</p>
  </blockquote>
  
  <p>Why this happens?</p>