Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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)
The key columns by which to order the results.
Zero or more parameters that are used in this method.
A new ObjectQuery<T> instance that is equivalent to the original instance with ORDER BY applied.
The keys
or parameters
parameter is null
.
keys
is an empty string.
This 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);
}
}
The ordering of results in a nested query cannot be guaranteed.
OrderBy should always be the final query builder method in the sequence.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in