Show / Hide Table of Contents

    ISqlOrderBuilder.OrderByAscending(params string[] orderExpressions) Method

    .NET Standard 2.x

    Creates an ORDER BY clause and specifies one or more sort criteria in ascending order.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlOrderThenBuilder OrderByAscending(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 OrderByAscending() method to retrieve all the records from the "Department" department and sort the records by budget in ascending order.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlOrderBuilderExamples
    {
        public class OrderByAscendingExample
        {
            private SchoolContext _context;
    
            public OrderByAscendingExample(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 "Department" table, 
                // and sorts the records by budget in ascending order.
                sqlbuilder.Select("*")
                    .From("Department", "dept")
                    .OrderByAscending("budget");
    
                // 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 [Department] AS [dept]
                ORDER BY
                [budget] ASC 
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon