ObjectQuery<T>.OrderBy(String, ObjectParameter[]) Method

Definition

Ordnet die Abfrageergebnisse nach den angegebenen Kriterien.Orders the query results by the specified criteria.

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

Parameters

keys
String

Die Schlüsselspalten, nach denen die Ergebnisse geordnet werden.The key columns by which to order the results.

parameters
ObjectParameter[]

Null oder mehr Parameter, die in dieser Methode verwendet werden.Zero or more parameters that are used in this method.

Returns

ObjectQuery<T>

Eine neue ObjectQuery<T>-Instanz, die der ursprünglichen Instanz entspricht, für die jedoch ORDER BY festgelegt ist.A new ObjectQuery<T> instance that is equivalent to the original instance with ORDER BY applied.

Exceptions

Der keys-Parameter oder der parameters-Parameter ist null.The keys or parameters parameter is null.

Der key ist eine leere Zeichenfolge.The key is an empty string.

Examples

Dieses Beispiel basiert auf den Microsoft SQL Server Product Samples: Database.This example is based on the Microsoft SQL Server Product Samples: Database. Im Beispiel wird ein neues ObjectQuery<T>-Objekt erstellt, das die Ergebnisse der vorhandenen Abfrage Reihenfolge ProductIDenthält.The example creates a new ObjectQuery<T> object that contains the results of the existing query order by ProductID.

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.OrderBy("it.ProductID");

    // Iterate through the collection of Product items.
    foreach (Product result in productQuery2)
    {
        Console.WriteLine("{0}", result.ProductID);
    }
}
Using context As New AdventureWorksEntities()
    Dim queryString As String = "SELECT VALUE product FROM AdventureWorksEntities.Products AS product"

    Dim productQuery1 As New ObjectQuery(Of Product)(queryString, context, MergeOption.NoTracking)

    Dim productQuery2 As ObjectQuery(Of Product) = productQuery1.OrderBy("it.ProductID")

    ' Iterate through the collection of Product items. 
    For Each result As Product In productQuery2
        Console.WriteLine("{0}", result.ProductID)
    Next
End Using

Remarks

Die Sortierung von Ergebnissen in einer geschachtelten Abfrage kann nicht garantiert werden.The ordering of results in a nested query cannot be guaranteed.

OrderBy sollte immer die endgültige Abfrage-Generator-Methode in der Sequenz sein.OrderBy should always be the final query builder method in the sequence.

Applies to

See also