SqlBuilder.OnRaw(string clause, string conditionName, params ISqlParameter[] parameters) Method
.NET Standard 2.x
Creates an ISqlJoinCondition
object which represents a search condition that can be used when building the ON clause. This search condition is specified by a raw SQL string. You need to specify a name for the raw SQL.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public static ISqlJoinCondition OnRaw(string clause, string conditionName, params ISqlParameter[] parameters);
Parameters
clause
System.String
A string of raw SQL to be added to the ON clause.
conditionName
System.String
The name for the raw SQL. It can be used to remove the raw SQL from ON clause.
parameters
SnapObjects.Data.ISqlParameter[]
(Optional) An array of ISqlParameter
objects which defines the SQL parameters used in the raw SQL.
Returns
SnapObjects.Data.ISqlJoinCondition
Returns the ISqlJoinCondition
object which can be used to add more search conditions to the ON clause.
Examples
The following code example uses the OnRaw method to set the condition (in raw SQL) for joining the "Department" table with the "Course" table.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.SqlBuilderExamples
{
public class OnRawExample
{
private SchoolContext _context;
public OnRawExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example2()
{
var sqlQueryBuilder = new SqlQueryBuilder();
// Defines a JOIN condition.
var join = SqlBuilder
.OnRaw("Department.DepartmentID = Course.DepartmentID and " +
"Course.DepartmentID > @dept",
"JoinTest",
SqlBuilder.Parameter<int>("dept"));
// Creates a SQL statement.
var query = sqlQueryBuilder
.Select("Department.DepartmentID")
.Select("Department.Name")
.Select("Course.Title")
.From("Department")
.Join("Course")
.On(join);
// Converts to raw SQL for the database corresponding to the data context.
string sql = query.ToSqlString(_context);
Console.WriteLine(sql);
/*This code produces the following output:
SELECT
[Department].[DepartmentID],
[Department].[Name],
[Course].[Title]
FROM [Department] JOIN [Course]
ON ([Department].[DepartmentID] = [Course].[DepartmentID]
AND [Course].[DepartmentID] > @dept)
*/
}
}
}
Applies to
.NET Standard
2.x