ISqlOrderThenBuilder.ThenByRaw(string orderClause, string alias) Method
.NET Standard 2.x
Adds one or more sort criteria specified by raw SQL to the ORDER BY
clause, and specifies an alias for the raw SQL.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlOrderThenBuilder ThenByRaw(string orderClause, string alias);
Parameters
orderClause
System.String
A string of raw SQL which specifies one or more sort criteria.
alias
System.String
The alias for the raw SQL.
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 ThenByRaw(string orderClause, string alias) method. It retrieves records from the "Course" table, sorts the records by DepartmentID in ascending order, and then sorts the records by Title in ascending order (using a raw SQL).
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlOrderThenBuilderExamples
{
public class ThenByRawExample
{
private SchoolContext _context;
public ThenByRawExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example2()
{
// Declares SqlQueryBuilder.
var sqlbuilder = new SqlQueryBuilder();
// Defines a SQL statement and retrieves all the records from the "Course" table.
// Sorts the records by DepartmentID in ascending order, and then sorts by Title in descending order.
// Specifies "ThenByDesc" as the alias for the ThenBy raw SQL.
sqlbuilder.Select("*")
.From("Course", "C")
.OrderByAscending("DepartmentID")
.ThenByRaw("Title desc", "ThenByDesc");
// 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