ObjectQuery<T>.Top(String, ObjectParameter[]) Yöntem

Tanım

Sorgu sonuçlarını belirtilen sayıda öğeyle sınırlar.

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)

Parametreler

count
String

Dize olarak sonuçlardaki öğe sayısı.

parameters
ObjectParameter[]

Ayrıştırma sırasında kapsamda olması gereken isteğe bağlı bir sorgu parametreleri kümesi.

Döndürülenler

TOP uygulanmış özgün örneğe eşdeğer yeni ObjectQuery<T> bir örnek.

Özel durumlar

count, null değeridir.

count boş bir dizedir.

Örnekler

Bu örnek, mevcut sorgunun ilk iki sonucunu içeren yeni ObjectQuery<T> bir oluşturur.

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);
}

Bu örnek, sorgu sonucundaki ilk üç nesneyi atladıktan sonra ölçütüne göre sıralanmış Product.ListPricebeş Product nesne alır. Top disk belleği için LIMIT yerine kullanılır.

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);
}

Açıklamalar

Top sorgu sıralanmadığı sürece belirleyici değildir.

yönteminden TopSkip sonra yöntemini kullandığınızda, ORDER BY yan tümcesinin LIMIT deyimi gibi çalışır.

Şunlara uygulanır

Ayrıca bkz.