6

I'm simply wondering why there is a IQueryable<T> version without the generic capability ?

Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145
  • 1
    Definition: "Provides functionality to evaluate queries against a specific data source wherein the type of the data is not specified.". For instance, you can return array of anonymous type from web api controller. – Vladimir Aug 30 '13 at 14:13

2 Answers2

5

The generic IQueryable<T> is the one you use most often in method signatures and the like. The non-generic IQueryable exist primarily to give you a weakly typed entry point primarily for dynamic query building scenarios.

by Matt Warren from LINQ: Building an IQueryable Provider - Part I

You should use generic IQueryable<T> everywhere it's possible.

MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
1

I imagine it's the same reason as Jon Skeet gives in Difference between IEnumerable and IEnumerable<T>? , to allow use in a foreach loop. IQuerable would be castable to IEnumerable, whereas IQueryable<T> would not.

Also see Marcin's answer about use in dynamic query building scenarios.

Community
  • 1
  • 1
neontapir
  • 4,698
  • 3
  • 37
  • 52
  • Type does not have to implement `IEnumerable` to be usable by `foreach` loop. – MarcinJuraszek Aug 30 '13 at 14:39
  • While technically true, I think it would be the easiest path to implementing those iterator hooks used under the covers. You could make the same argument for any of the other iterator types mentioned in the SO question I quoted. – neontapir Aug 30 '13 at 14:55