standards-c-sharp

Usage of IQueryable<T>

In WebApi

Return IQueryable<T> from a WebApi endpoint when you want to allow artitrary server-side filtering and paging. For example, to allow the client to arbitrarily query the products database:

public IQueryable<Product> Get() 
{
    return allProducts.AsQueryable();
}

The client can then construct arbitrary queries such as:

In a class library

Return IQueryable<T> from a class library when all of the following are true:

An example is a LINQ to SQL provider. The C# expression tree provided by the consumer is translated into actual SQL statements that can be executed by the target database. Note: this is a dark art and not for the faint-hearted.