Show / Hide Table of Contents

    IDataStore.SortByDescending<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

    IOrderable<TModel> SortByDescending<TModel>(Func<TModel, object> keySelector);
    

    Type Parameters

    TModel

    The type of a model class that matches with the current DataObject.

    Parameters

    keySelector Func<TModel, long>

    A function to extract the key from a row.

    Returns

    DWNet.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 data records by budget in the descending order.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class SortByDescendingExample
        {
            private readonly SchoolContext _context;
    
            public SortByDescendingExample(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();
    
                foreach (var item in datastore)
                {
                    Console.WriteLine("Before Sort, Budget:{0}", ((D_Department)item).Budget);
                }
    
                // Specifies key in descending order.
                datastore.SortByDescending<D_Department>(a => a.Budget);
                // Sorts DataStore in descending order.
                datastore.Sort();
    
                foreach (var item in datastore)
                {
                    Console.WriteLine("After Sort, Budget:{0}", ((D_Department)item).Budget);
                }
    
                /*This code produces the following output:
                
                Before Sort, Budget: 350000.00
                Before Sort, Budget: 120000.00
                Before Sort, Budget: 200000.00
                Before Sort, Budget: 250000.00
                After Sort, Budget: 350000.00
                After Sort, Budget: 250000.00
                After Sort, Budget: 200000.00
                After Sort, Budget: 120000.00
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Back to top Generated by Appeon