ObjectQuery<T>.Top(String, ObjectParameter[]) 메서드

정의

지정된 개수의 항목으로 쿼리 결과를 제한합니다.

public:
 System::Data::Objects::ObjectQuery<T> ^ Top(System::String ^ count, ... cli::array <System::Data::Objects::ObjectParameter ^> ^ parameters);
public System.Data.Objects.ObjectQuery<T> Top (string count, params System.Data.Objects.ObjectParameter[] parameters);
member this.Top : string * System.Data.Objects.ObjectParameter[] -> System.Data.Objects.ObjectQuery<'T>
Public Function Top (count As String, ParamArray parameters As ObjectParameter()) As ObjectQuery(Of T)

매개 변수

count
String

문자열 형태의 결과 항목 개수입니다.

parameters
ObjectParameter[]

구문 분석 범위에 포함되어야 하는 쿼리 매개 변수의 선택적 집합입니다.

반환

원래 인스턴스에 TOP이 적용된 것과 동일한 새 ObjectQuery<T> 인스턴스입니다.

예외

count이(가) null인 경우

count이 빈 문자열인 경우

예제

이 예제에서는 기존 쿼리의 처음 두 결과를 포함하는 새 ObjectQuery<T> 를 만듭니다.

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString =
        @"SELECT VALUE product FROM AdventureWorksEntities.Products AS product";

    ObjectQuery<Product> productQuery1 =
        new ObjectQuery<Product>(queryString, context, MergeOption.NoTracking);

    ObjectQuery<Product> productQuery2 = productQuery1.Top("2");

    // Iterate through the collection of Product items.
    foreach (Product result in productQuery2)
        Console.WriteLine("{0}", result.Name);
}

이 예제에서는 쿼리 결과에서 처음 3개를 건너뛰고 을 기준으로 정렬된 5개의 Product 개체를 Product.ListPrice가져옵니다. Top 는 페이징에 LIMIT 대신 사용됩니다.

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    // Define the parameters used to define the "page" of returned data.
    int skipValue = 3;
    int limitValue = 5;

    // Define a query that returns a "page" or the full
    // Product data using the Skip and Top methods.
    // When Top() follows Skip(), it acts like the LIMIT statement.
    ObjectQuery<Product> query = context.Products
        .Skip("it.ListPrice", "@skip",
                new ObjectParameter("skip", skipValue))
        .Top("@limit", new ObjectParameter("limit", limitValue));

    // Iterate through the page of Product items.
    foreach (Product result in query)
        Console.WriteLine("ID: {0}; Name: {1}",
        result.ProductID, result.Name);
}

설명

Top 은 쿼리를 정렬하지 않는 한 비결정적입니다.

메서드 다음에 메서드를 TopSkip 사용하면 ORDER BY 절의 LIMIT 문처럼 작동합니다.

적용 대상

추가 정보