views:

978

answers:

1

ExecuteQuery() method returns an IEnumerable but is there a way to make it return IQueryable?

+1  A: 

Well, you can call AsQueryable, but it won't do any good. The problem is that when you use ExecuteQuery, the query isn't composable because LINQ to SQL doesn't "understand" it as such.

One of the core purposes of IQueryable<T> is to allow the various aspects of a query to be composed together and then LINQ to SQL can convert them into a single SQL query. That just doesn't work when one of the bits of the query is effectively opaque.

Jon Skeet
You seem to understand my exact problem. Is there any way around this if I want to use ad-hoc queries?
codette
Not if you want to use them as part of other queries, as far as I'm aware. It's possible you could write a stored procedure and call *that* in a composable way, providing the SQL as a parameter, but it would be pretty horrible.
Jon Skeet