Share via


Using the Take() function

[This document supports a preliminary release of a software product that may be changed substantially prior to final commercial release. This document is provided for informational purposes only.]

Take() function can be added to a query to restrict the number of entities returned. For example, the following query returns all the entities of "Customer" Kind from a given scope.

from e in entities where e.Kind == "Customer" select e

The following query limits the number of entities returned to 10 by adding the Take() function in the expression.

(from e in entities where e.Kind == "Customer" select e).Take(10)

By default the query results are sorted by Id metadata property. Therefore, the query returns top 10 customer entities by id. The query expression can also be written as

Take(from e in entities where e.Kind == "Customer" select e, 10)

The Take() function is also useful when dealing with queries that return large result sets. You can retrieve this result in smaller chunks called pages. You can set the page size using the Take() function. For more information, see Paging Support to Handle Large Query Results.

See Also

Concepts

Querying SQL Data Services
Paging Support to Handle Large Query Results