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

定義

指定された条件でクエリの結果を並べ替えます。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)

パラメーター

keys
String String String String

結果の並べ替えに使用するキー列。The key columns by which to order the results.

parameters
ObjectParameter[]

このメソッドで使用される 0 個以上のパラメーター。Zero or more parameters that are used in this method.

戻り値

ORDER BY が適用された元のインスタンスに相当する、新しい ObjectQuery<T> インスタンス。A new ObjectQuery<T> instance that is equivalent to the original instance with ORDER BY applied.

例外

keys パラメーターまたは parameters パラメーターが null です。The keys or parameters parameter is null.

key が空の文字列です。The key is an empty string.

この例は、 AdventureWorks Sales Modelに基づいています。This example is based on the AdventureWorks Sales Model. この例では、 ObjectQuery<T>によるProductID既存のクエリ順序の結果を含む新しいオブジェクトを作成します。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

注釈

入れ子になったクエリでの結果の並べ替えは保証されません。The ordering of results in a nested query cannot be guaranteed.

OrderBy は、常にシーケンスにおける最後のクエリ ビルダー メソッドである必要があります。OrderBy should always be the final query builder method in the sequence.

適用対象

こちらもご覧ください