SqlBuilder.WhereRaw(string clause, params ISqlParameter[] parameters) Method
.NET Standard 2.x
Creates an ISqlWhereCondition
object which represents a search condition that can be used when building the WHERE clause. This search condition is specified by a raw SQL string.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public static ISqlWhereCondition WhereRaw(string clause, params ISqlParameter[] parameters);
Parameters
clause
System.String
A string of raw SQL to be added to the WHERE clause.
parameters
SnapObjects.Data.ISqlParameter[]
(Optional) An array of ISqlParameter
objects which defines the SQL parameters used in the raw SQL.
Returns
SnapObjects.Data.ISqlWhereCondition
Returns the ISqlWhereCondition
object which can be used to add more search conditions to the WHERE clause.
Examples
The following code example demonstrates how to use the WhereRaw method to specify a WHERE condition in a raw SQL string.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.SqlBuilderExamples
{
public class WhereRawExample
{
private SchoolContext _context;
public WhereRawExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example1()
{
var sqlquerybuilder = new SqlQueryBuilder();
// Defines a WHERE condition.
var where = SqlBuilder
.WhereRaw("DepartmentID = :id", SqlBuilder.Parameter<int>("id"));
// Creates a SQL statement.
var query = sqlquerybuilder
.Select("*")
.From("Department")
.Where(where);
// 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
*
FROM [Department]
WHERE ([DepartmentID] = @id)
*/
}
}
}
Applies to
.NET Standard
2.x