ISqlWhereBuilder.WhereRaw(string whereClause, string whereName, params ISqlParameter[] parameters) Method
.NET Standard 2.x
Creates a WHERE clause, adds a raw SQL to the WHERE clause, and specifies a name for the raw SQL.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlWhereAndOr WhereRaw(string whereClause, string whereName, params ISqlParameter[] parameters);
Parameters
whereClause
System.String
A string of raw SQL to be added to the WHERE clause.
whereName
System.String
The name for the raw SQL. It can be used to remove the raw SQL from 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.ISqlWhereAndOr
Returns the ISqlWhereAndOr
object which can be used to add more search conditions to the current WHERE clause.
Examples
The following code example uses the WhereRaw method to build the WHERE condition in a raw SQL and specify an alias for the WHERE condition.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlWhereBuilderExamples
{
public class WhereRawExample
{
private readonly SchoolContext _context;
public WhereRawExample(SchoolContext dataContext)
{
// Sets data context.
_context = dataContext;
}
public void Example2()
{
// Declares SqlQueryBuilder.
var sqlbuilder = new SqlQueryBuilder();
// Defines a SQL statement, and specifies the WHERE condition in a raw SQL: Title = @titlename.
// Specifies "where1" as the alias for the WHERE condition.
sqlbuilder.Select("*")
.From("Course")
.WhereRaw("Title = @titlename", "where1",
SqlBuilder.Parameter<string>("titlename"));
string sql = sqlbuilder.ToSqlString(_context);
Console.WriteLine(sql);
/*This code produces the following output:
SELECT
*
FROM [Course]
WHERE ([Title] = @titlename)
*/
}
}
}
Applies to
.NET Standard
2.x