ISqlJoinOnAndOr<TBuilder>.OrOn(ISqlJoinCondition condition) Method
.NET Standard 2.x
Adds the OR
logical operator and a search condition (specified by an ISqlJoinCondition
object) to the ON clause.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
TBuilder OrOn(ISqlJoinCondition condition);
Parameters
condition
SnapObjects.Data.ISqlJoinCondition
An ISqlJoinCondition
object which represents a search condition in the ON Clause.
This object can be created by using the SqlBuilder.On
method and so on.
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 Example7()
{
var sqlQueryBuilder = new SqlQueryBuilder();
// Defines a JOIN condition.
var joinOnCondtion =
SqlBuilder.EmbeddedOnRaw("Department.DepartmentID = 1");
// Gets DepartmentID values and Name values from the "Department" table, and Title values from the "Course" table.
// Sets the condition to join the "Department" table and the "Course" table:
// Department.DepartmentID = Course.DepartmentID, or the condition defined aboved (Department.DepartmentID = 1).
sqlQueryBuilder
.Select("Department.DepartmentID")
.Select("Department.Name")
.Select("Course.Title")
.From("Department")
.Join("Course")
.OnRaw("Department.DepartmentID = Course.DepartmentID")
.OrOn(joinOnCondtion);
// Converts to raw SQL for the database corresponding to the data context.
string sql = sqlQueryBuilder.ToSqlString(_context);
Console.WriteLine(sql);
/*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] = 1)
*/
}
}
}
Applies to
.NET Standard
2.x