ISqlJoinOnBuilder.On(string left, ISqlBuilder sqlBuilder) Method
.NET Standard 2.x
Creates an ON
clause and adds a search condition to it. Specifies the SQL expression on the left of the operator and the SQL subquery on the right. The operator is '='.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlJoinOnAndOr On(string left, ISqlBuilder sqlBuilder);
Parameters
left
System.String
A SQL expression on the left of the operator.
sqlBuilder
SnapObjects.Data.ISqlBuilder
An ISqlBuilder
object which represents a SQL subquery on the right of the operator.
Returns
SnapObjects.Data.ISqlJoinOnAndOr
Returns the ISqlJoinOnAndOr
object which can be used to add more search conditions to the current ON
clause.
Examples
The following code example uses the On method to set Sets the condition to join one table with another.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlJoinOnBuilderExamples
{
public class OnExample
{
private readonly SchoolContext _context;
public OnExample(SchoolContext dataContext)
{
// Sets data context.
_context = dataContext;
}
public void Example5()
{
ISqlQueryBuilder sqlQueryBuilder = new SqlQueryBuilder();
// Sets a query to get the largest DepartmentID.
ISqlQueryBuilder sqlBuilder = new SqlQueryBuilder();
sqlBuilder.SelectRaw("max(DepartmentID)")
.From("Department");
// Gets DepartmentID values and Name values from the "Department" table,
// and the Title values from the "Course" table.
// Sets the condition to join the "Department" and "Course" tables:
// Department.DepartmentID equal to the largest DepartmentID returned from the query.
sqlQueryBuilder
.Select("Department.DepartmentID")
.Select("Department.Name")
.Select("Course.Title")
.From("Department")
.Join("Course")
.On("Department.DepartmentID", sqlBuilder);
// 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] = (SELECT
MAX([DepartmentID])
FROM [Department])
*/
}
}
}
Applies to
.NET Standard
2.x