ObjectQuery<T>.Top(String, ObjectParameter[]) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
쿼리 결과를 지정된 수의 항목으로 제한합니다.
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 문처럼 작동합니다.