ISqlJoinOnAndOr<TBuilder>.AndOnValue(string left, SqlBinaryOperator sqlOperator, object value) Method
.NET Standard 2.x
Adds the AND
logical operator and a search condition to the ON clause; and specifies a SQL expression on the left the operator and a specific value on the right of the operator.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
TBuilder AndOnValue(string left, SqlBinaryOperator sqlOperator, object value);
Parameters
left
System.String
An expression on the left of the operator.
SqlBinaryOperator
SnapObjects.Data.SqlBinaryOperator
An enumeration value of SqlBinaryOperator
, which is the operator to test the expression on the left and the value on the right.
value
System.Object
A specific value on the right of the operator.
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 AndOnValue method to add more conditions.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlJoinOnAndOrExamples
{
public class AndOnValueExample
{
private readonly SchoolContext _context;
public AndOnValueExample(SchoolContext dataContext)
{
// Sets data context.
_context = dataContext;
}
public void Example2()
{
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 > 2000.
sqlQueryBuilder
.Select("Department.DepartmentID")
.Select("Department.Name")
.Select("Course.Title")
.From("Department")
.Join("Course")
.OnRaw("Department.DepartmentID = Course.DepartmentID")
.AndOnValue("Course.CourseID", SqlBinaryOperator.GreaterThan, 2000);
// 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]
AND [Course].[CourseID] > = 2000
*/
}
}
}
Applies to
.NET Standard
2.x