title: IQueryable<> from stored procedure (entity framework)
body: <p>I want to get <code>IQueryable&lt;&gt;</code> result when executing stored procedure.  </p>
  
  <p>Here is piece of code that works fine:  </p>
  
  <pre><code>IQueryable&lt;SomeEntitiy&gt; someEntities;  
  var globbalyFilteredSomeEntities = 
    from se in m_Entities.SomeEntitiy
      where
        se.GlobalFilter == 1234 
    select se;
  </code></pre>
  
  <p>I can use this to apply global filter, and later use the result in something like:  </p>
  
  <pre><code>result = globbalyFilteredSomeEntities
    .OrderByDescending(se =&gt; se.CreationDate)
    .Skip(500)
    .Take(10);
  </code></pre>
  
  <hr>
  
  <p>What I want to do - use some stored procedures in global filter.<br>
  I tried:  </p>
  
  <p>Add stored procedure to <code>m_Entities</code>, but it returns <code>IEnumerable&lt;&gt;</code> and executes sp immediately:  </p>
  
  <pre><code>var globbalyFilteredSomeEntities = 
    from se in m_Entities.SomeEntitiyStoredProcedure(1234);
  </code></pre>
  
  <p>Materialize query using EFExtensions library, but it is <code>IEnumerable&lt;&gt;</code>.<br>
  If I use <code>AsQueryable()</code> and <code>OrderBy()</code>, <code>Skip()</code>, <code>Take()</code><br>
  and after that <code>ToList()</code> to execute that query -<br>
  I get exception that <code>DataReader</code> is open and I need to close it first(can't paste error - it is in russian).</p>
  
  <pre><code>var globbalyFilteredSomeEntities = 
    m_Entities.CreateStoreCommand("exec SomeEntitiyStoredProcedure(1234)")
              .Materialize&lt;SomeEntitiy&gt;();
              //.AsQueryable()
              //.OrderByDescending(se =&gt; se.CreationDate)
              //.Skip(500)
              //.Take(10)
              //.ToList();   
  </code></pre>
  
  <p>Also just skipping <code>.AsQueryable()</code> is not helpful - same exception.<br>
  When I put <code>ToList()</code> query executes,<br>
  but it is too expensive to execute query without <code>Skip()</code>, <code>Take()</code>.</p>