IQueryable and IQueryable<T>
are abstractions that encapsulate LINQ expressions; these expressions are then used by a LINQ provider - like the one used by Entity Framework - to turn these expressions into SQL that will, in turn, be sent to the database. Different LINQ providers interpret LINQ expressions differently, for example, MongoDB's turns these expressions into JSON queries.
IQueryable
s are only evaluated when a "terminal" method is called upon them, like, ToList()
, ToArray()
, Single()
, SingleOrDefault()
, First()
, FirstOrDefault()
, Count()
, Any()
, etc. This is when the provider quicks in and does the translation.
Microsoft includes a LINQ provider, which does not do a translation to anything, but operates in memory. This is the one used when you turn an IEnumerable<T>
into an IQueryable<T>
, by calling the extension method AsQueryable()
.