Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IQueryable vs IQueryable<T>

Tags:

c#

iqueryable

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

like image 677
Guillaume Paris Avatar asked Aug 30 '13 14:08

Guillaume Paris


2 Answers

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.

like image 180
MarcinJuraszek Avatar answered Oct 24 '22 16:10

MarcinJuraszek


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.

like image 44
neontapir Avatar answered Oct 24 '22 16:10

neontapir