title: Entity Framework query with *sql* subquery
body: <p>In short: can I use a literal SQL subquery somehow in the entity model without using database views?</p>
  
  <p>Context: I have a bunch of ADO.NET queries that result in C# objects.  These objects correspond directly to the query shape; i.e. I can do <a href="http://msdn.microsoft.com/en-us/library/dd466384" rel="nofollow"><code>ObjectContext.Translate</code></a> to extract them from the <code>SqlDataReader</code>.  There are lots of these queries, many quite complex, and some of which use features the entity framework doesn't support (while loops, CTE's, hierarchyids, etc.) - converting these (legacy) queries to LINQ isn't feasible.</p>
  
  <p>However, I'd really like to be able wrap these results and add some custom filtering on the C# side of things: things like sorting, filtering, paging etc.  I could convert each and every query into a view (or stored procedure) and map these, but that's a hassle and a maintenance nightmare - but in principle EF can be used with "opaque" SQL queries by that route.</p>
  
  <p>Can I somehow use subqueries written in SQL with the entity model?  An <code>ObjectContext.Translate</code> that returns an <code>IQueryable</code> rather than an <code>IEnumerable</code> would be ideal, but not necessary: the vast majority of queries are compile-time constants, so some form of pre-processing is possible.</p>
  
  <p><em><strong>Edit:</em></strong> I'm looking for something returning an <code>IQueryable</code> so I can add filters/sorting client side but have them executed on the DB (as usual).  I'm using Entity Framework code-first.</p>