IQueryable and IQueryable(Of T) Interfaces
The IQueryable and IQueryable(Of T) interfaces provide the functionality to evaluate queries for a
given data source. The IQueryable interface does this where the type of the data is not known, and the
IQueryable(Of T) interface does this where the type of the data is known.
The IQueryable and IQueryable(Of T) interfaces implement the IEnumerable and
IEnumerable(Of T)
interface, respectively, providing the capability of enumeration over the results of the given query. As
you have learned previously, the enumeration causes the expression tree associated with an IQueryable
or IQueryable(Of T) object to be executed. Keep in mind that the term ‘‘executing an expression tree’’ is
specific to the query provider.
The difference between these two interfaces is that the IQueryable(Of T) interface enables queries
to be executed against different types of data sources. These queries are commonly referred to
as ‘‘polymorphic.’’
Keep in mind that both the IQueryable and IQueryable(Of T) interfaces are intended for
implementation only by query providers. Think of an IQueryable object as having an ADO.NET command
object. Having one (either an IQueryable object or a command object) does not insinuate that either the
LINQ query (or the command) was executed.
Let’s take a close look at each of these to help understand the IQueryable object. An ADO.NET
command object contains a property that holds a string that describes the query. The IQueryable
object is similar in that it contains a description of a query that is encoded as a data structure known
as an expression.
The command object has an ExecuteReader() method that causes execution. The results are returned as
a DataReader. Likewise, the IQueryable object has a GetEnumerator method that causes the execution of
the query. The results of the query are returned as an IEnumerator.

浙公网安备 33010602011771号