ObjectQuery<T>::Top Method (String^, array<ObjectParameter^>^)

 

Limits the query results to a specified number of items.

Namespace:   System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public:
ObjectQuery<T>^ Top(
	String^ count,
	... array<ObjectParameter^>^ parameters
)

Parameters

count
Type: System::String^

The number of items in the results as a string.

parameters
Type: array<System.Data.Objects::ObjectParameter^>^

An optional set of query parameters that should be in scope when parsing.

Return Value

Type: System.Data.Objects::ObjectQuery<T>^

A new ObjectQuery<T> instance that is equivalent to the original instance with TOP applied.

Exception Condition
ArgumentNullException

count is null.

ArgumentException

count is an empty string.

Top is nondeterministic unless the query is sorted.

When you use the Top method after the Skip method, it functions like the LIMIT statement of an ORDER BY clause.

These examples are based on the AdventureWorks Sales Model.

This example creates a new ObjectQuery<T> that contains the first two results of the existing query.

No code example is currently available or this language may not be supported.

This example gets five Product objects after skipping the first three in the query result, sorted by Product.ListPrice. Top is used instead of LIMIT for paging.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.5
Return to top
Show: