Show / Hide Table of Contents

    ISqlOrderThenBuilder.ThenByDescending(params string[] orderExpressions) Method

    .NET Standard 2.x

    Adds one or more sort criteria (in descending order) to the ORDER BY clause.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlOrderThenBuilder ThenByDescending(params string[] orderExpressions);
    

    Parameters

    orderExpressions System.String[]

    (Optional) An array of expressions which specify a column or an expression on which to sort the query result set.

    Returns

    SnapObjects.Data.ISqlOrderThenBuilder

    Returns an ISqlOrderThenBuilder object which can be used to add more sort criteria to the current ORDER BY clause.

    Examples

    The following code example demonstrates how to use the ThenByDescending() method. It retrieves the records from the "Course" table, sorts the records by DepartmentID in ascending order, and then sorts the records by Title in descending order.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlOrderThenBuilderExamples
    {
        public class ThenByDescendingExample
        {
            private SchoolContext _context;
    
            public ThenByDescendingExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example()
            {
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement; retrieves all the records from the "Course" table, 
                // sorts records by DepartmentID in ascending order, then sorts by Title in descending order.
                sqlbuilder.Select("*")
                    .From("Course", "C")
                    .OrderByAscending("DepartmentID")
                    .ThenByDescending("Title");
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
                
                /*This code produces the following output:
                
                SELECT
                *
                FROM [Course] AS [C]
                ORDER BY
                [DepartmentID] ASC,
                [Title] DESC
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon