IDataStore.OrderByDescending<TModel>(Func<TModel, object> keySelector) Method
.NET Standard 2.x
Sorts the rows of the primary buffer in the DataStore by a key in the descending order.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public IOrderable<TModel> OrderByDescending<TModel>(Func<TModel, object> keySelector);
Type Parameters
TModel
The type of a model
class that matches with the current DataObject
.
Parameters
keySelector
System.Func<TModel, System.Object>
A function to extract the key from a row.
Returns
SnapObjects.Data.IOrderable<TModel>
Returns an IOrderable<TModel>
object which provides methods to add other sorting conditions or execute sort.
Examples
The following code example sorts the DataStore records by budget in the descending order.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class OrderByDescendingExample
{
private readonly SchoolContext _context;
public OrderByDescendingExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
datastore.Retrieve();
Console.WriteLine("Before OrderBy");
for (int row = 0, rowcount = datastore.RowCount; row < rowcount; row++)
{
Console.WriteLine(
"Department ID: {0}; Department Name: {1}; Budget: {2}",
datastore.GetItem<int>(row, 0),
datastore.GetItem<string>(row, 1),
datastore.GetItem<decimal>(row, 2));
}
// Sorts records by budget in descending order
datastore.OrderByDescending<D_Department>(d => d.Budget).Sort();
Console.WriteLine("After OrderBy");
for (int row = 0, rowcount = datastore.RowCount; row < rowcount; row++)
{
Console.WriteLine(
"Department ID: {0}; Department Name: {1}; Budget: {2}",
datastore.GetItem<int>(row, 0),
datastore.GetItem<string>(row, 1),
datastore.GetItem<decimal>(row, 2));
}
/*This code produces the following output:
Before OrderBy
Department ID: 1; Department Name: Engineering; Budget: 350000.0000
Department ID: 2; Department Name: English; Budget: 120000.0000
Department ID: 4; Department Name: Economics; Budget: 200000.0000
Department ID: 7; Department Name: Mathematics; Budget: 250000.0000
After OrderBy
Department ID: 1; Department Name: Engineering; Budget: 350000.0000
Department ID: 7; Department Name: Mathematics; Budget: 250000.0000
Department ID: 4; Department Name: Economics; Budget: 200000.0000
Department ID: 2; Department Name: English; Budget: 120000.0000
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x