IEnumerable<T>
There many different ways that a set of things can be stored, in a List, in an Array, in a database etc. One thing that these storage mechanisms have in common is that the set of things being held can be Enumerated, that is each one can be accessed one after the other using a language construct such as foreach
for example.
The IEnumerable<T>
interface represents that common interface that all holders of sets of things have to enable enumeration. Hence IEnumberable<Person
represents an interface that allows enumeration of a Set of Person
objects without being specific about the actual manner in which those objects are stored.
IQueryable<T>
This is an extension to IEnumerable<T>
but represents something specific to LINQ. In LINQ you can specify a query that can filter and transform a set (or sets) of items. Against a purely IEnumerable<T>
interface this would be known as LINQ to Objects, in which each stage in the query is ultimately a simple call to an extension method.
However against an object that implements IQueryable<T>
things can be more sophisticated. The object implementing IQueryable<T>
can be associated with a different LINQ Provider which may implement the execution of LINQ queries in a different way. For example IQueryable<Person>
may be implemented by a type associated with the LINQ-To-SQL provider. In this case a LINQ query is transformed to a T-SQL query an executed against a database to get a set of items (the result may not necessarily be a set of Person
objects).