SqlBuilder.SelectRaw(string selectRaw, params ISqlParameter[] parameters) Method
.NET Standard 2.x
Creates an ISqlQueryBuilder
object for building a SQL SELECT statement, and adds a raw SQL to the select list of the SELECT clause.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public static ISqlQueryBuilder SelectRaw(string selectRaw, params ISqlParameter[] parameters);
Parameters
selectRaw
System.String
A string of raw SQL to be added to the SELECT clause.
Actually, you can write any raw SQL if the SQL statement is valid.
parameters
SnapObjects.Data.ISqlParameter[]
(Optional) An array of ISqlParameter
objects which defines the SQL parameters used in the raw SQL.
Returns
SnapObjects.Data.ISqlQueryBuilder
Returns a newly created ISqlQueryBuilder
object which can be used to build the SQL SELECT statement.
Examples
The following code example demonstrates how to use the SelectRaw(string selectRaw, params ISqlParam[] parameters)
method to select columns in raw SQL, and select a customized column whose value will be supplied dynamically.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.SqlBuilderExamples
{
public class SelectRawExample
{
private SchoolContext _context;
public SelectRawExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example()
{
// Creates a SQL statement.
var query = SqlBuilder
.SelectRaw("name, budget,selected = @a",
SqlBuilder.Parameter<int>("a"))
.From("Department");
// Converts to raw SQL for the database corresponding to the data context.
string sql = query.ToSqlString(_context);
Console.WriteLine(sql);
/*This code example produces the following output:
SELECT
[name],
[budget],
[selected] = @a
FROM [Department]
*/
}
}
}
Applies to
.NET Standard
2.x