ISqlJoinOnAndOr<TBuilder>.OrOn(string left, SqlBinaryOperator sqlOperator, ISqlParameter parameter) Method
.NET Standard 2.x
Adds the OR
logical operator and a search condition to the ON clause; and specifies a SQL expression on the left of the operator and a SQL parameter on the right of the operator.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
TBuilder OrOn(string left, SqlBinaryOperator sqlOperator, ISqlParameter parameter);
Parameters
left
System.String
A SQL expression on the left of the operator.
SqlBinaryOperator
SnapObjects.Data.SqlBinaryOperator
An enumeration value of SqlBinaryOperator
, which is the operator to test the two expressions on the left and right.
parameter
SnapObjects.Data.ISqlParameter
An ISqlParameter
object which represents a SQL parameter on the right of the operator.
It can be created by calling the SqlBuilder.Parameter method.
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 OR conditions. It uses the OrOn method to add the OR condition.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlJoinOnAndOrExamples
{
public class OrOnExample
{
private readonly SchoolContext _context;
public OrOnExample(SchoolContext dataContext)
{
// Sets data context.
_context = dataContext;
}
public void Example4()
{
var sqlQueryBuilder = new SqlQueryBuilder();
// Gets 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, or Department.DepartmentID greater than the input argument.
sqlQueryBuilder
.Select("Department.DepartmentID")
.Select("Department.Name")
.Select("Course.Title")
.From("Department")
.Join("Course")
.OnRaw("Department.DepartmentID = Course.DepartmentID")
.OrOn("Department.DepartmentID",
SqlBinaryOperator.GreaterThan,
SqlBuilder.Parameter<int>("departmentid"));
// 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, 1);
/*This code example produces the following output:
SELECT
[Department].[DepartmentID],
[Department].[Name],
[Course].[Title]
FROM [Department] JOIN [Course]
ON [Department].[DepartmentID] = [Course].[DepartmentID]
OR [Department].[DepartmentID] > @departmentid
*/
}
}
}
Applies to
.NET Standard
2.x