views:

340

answers:

4

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?

+5  A: 

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.

Andrew Hare
+10  A: 

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.)

Jon Skeet
+3  A: 

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.

Welbog
A: 

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&amp;q=i+love+linq&amp;aq=f&amp;oq=&amp;aqi=g10

Then you parse the page to get the results.

Nicolas Dorier