ISqlJoinOnAndOr<TBuilder>.AndOnRaw(string clause, params ISqlParameter[] parameters) Method
.NET Standard 2.x
Adds the AND
logical operator and a raw SQL to the ON clause.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
TBuilder AndOnRaw(string clause, params ISqlParameter[] parameters);
Parameters
clause
System.String
A string of raw SQL to be added to the ON clause.
parameters
SnapObjects.Data.ISqlParameter
(Optional) An array of ISqlParameter
objects which define the SQL parameters used in the raw SQL.
Returns
TBuilder
Returns the TBuilder
object which can be used to add more search conditions to the current ON clause.
Examples
The following code example joins one table with another based on multiple conditions. It uses the AndOnRaw method to add more conditions (in raw SQL).
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlJoinOnAndOrExamples
{
public class AndOnRawExample
{
private readonly SchoolContext _context;
public AndOnRawExample(SchoolContext dataContext)
{
// Sets data context.
_context = dataContext;
}
public void Example()
{
var sqlQueryBuilder = new SqlQueryBuilder();
// Gets the DepartmentID values and Name values from the "Department" table, and Title values from the "Course" table.
// Sets the condition to join the "Department" and "Course" tables:
// Department.DepartmentID = Course.DepartmentID, and Course.CourseID greater than the input argument.
sqlQueryBuilder
.Select("Department.DepartmentID")
.Select("Department.Name")
.Select("Course.Title")
.From("Department")
.Join("Course")
.OnRaw("Department.DepartmentID = Course.DepartmentID")
.AndOnRaw("Course.CourseID > @courseid",
SqlBuilder.Parameter<int>("courseid"));
// Converts to raw SQL for the database corresponding to the data context.
string sql = sqlQueryBuilder.ToSqlString(_context);
Console.WriteLine(sql);
// Executes the SQL statement, and specifies the value for the input argument.
var departments = _context.SqlExecutor.Select<DynamicModel>(sql, 2000);
/*This code example produces the following output:
SELECT
[Department].[DepartmentID],
[Department].[Name],
[Course].[Title]
FROM [Department] JOIN [Course]
ON [Department].[DepartmentID] = [Course].[DepartmentID]
AND [Course].[CourseID] > @courseid
*/
}
}
}
Applies to
.NET Standard
2.x