IQueryable<T>

You will see that in many of the LINQ to SQL examples in this chapter and the subsequent LINQ to SQL chapters, I work with sequences of type IQueryable<T>, where T is the type of an entity class. These are the type of sequences that are typically returned by LINQ to SQL queries. They will often appear to work just like an IEnumerable<T> sequence, and that is no coincidence. The IQueryable<T> interface implements the IEnumerable<T> interface. Here is the definition of IQueryable<T>:

interface IQueryable<T> : IEnumerable<T>, IQueryable

Because of this inheritance, you can treat an IQueryable<T> sequence like an IEnumerable<T> sequence.

Get Pro LINQ: Language Integrated Query in C# 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.