Accepted answer

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 :

then you parse the page to get the results.


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 haven't used expression trees before, they're basically data structures describing the code - whereas a delegate is the code itself. so you can execute a delegate, but you can examine an expression tree to see what it would do.)

Related Query

More Query from same tag