There's this. Can you do a better job explaining (in small words so I understand :)) why we need a marker interface which doesn't add any methods over IEnumerable?
IQueryable<T>
is needed because it defines a contract that is required for a LINQ provider. Many of the extension methods available on IQueryable<T>
are designed to accept expressions rather than delegates.
This is important as a LINQ provider will need to analyze the expression tree rather than invoke a delegate.
IQueryable<T>
also extends IQueryable
. Basically it's an IQueryable
which can be enumerated in a strongly-typed way. (Both IQueryable
and IEnumerable<T>
already extend IEnumerable
, so it's not adding anything on that front.)
Now, having a strongly-typed IQueryable
allows LINQ to SQL (etc) to be strongly typed - otherwise you couldn't write Where
clauses etc without casting. The actual LINQ methods involved are in the Queryable
type, largely mirroring the Enumerable
methods but taking expression trees instead of delegates. (If you're not comfortable with what expression trees are, say so and I'll try to add a quick explanation of them.)
It extends IEnumerable
, IQueryable
and IEnumerable<T>
. It may not have methods of its own, but it aggregates these other three interfaces as one, so you don't have to deal with them separately.
Use IQueryable if you want to translate a linq query to an expression tree (System.Linq). From an expression tree you can easily translate your LINQ query to another language (SQL for Linq To SQL. Another classic example is Linq to Google where you want this query :
var searchResult = from result in Google.Repository where result.Equals("i love linq") select result;
To translate to this url :
http://www.google.com/search?hl=en&q=i+love+linq&aq=f&oq=&aqi=g10
Then you parse the page to get the results.