ISqlGroupBuilder.OrderByRaw(string orderClause, string alias) Method
.NET Standard 2.x
Creates an ORDER BY
clause; and specifies one or more sort criteria using a raw SQL and specifies an alias for the raw SQL.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlOrderThenBuilder OrderByRaw(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 OrderByRaw(string orderClause, string alias) method to retrieve all the records from the "Department" department, specifies the sorting order in a raw SQL, and sets an alias for the raw SQL.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlOrderBuilderExamples
{
public class OrderByRawExample
{
private SchoolContext _context;
public OrderByRawExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example2()
{
// 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 descending order.
// Specifies "OrderByDESC" as the alias for the OrderBy raw SQL.
sqlbuilder.Select("*")
.From("Department", "dept")
.OrderByRaw("budget desc", "OrderByDESC");
// 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] DESC
*/
}
}
}
Applies to
.NET Standard
2.x