ISqlWhereAndOr<TBuilder>.OrWhere(string left, SqlBinaryOperator sqlOperator, string right) Method
.NET Standard 2.x
Adds the OR
logical operator and a search condition to the WHERE clause; and specifies SQL expressions on both the left and right of the operator.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
TBuilder OrWhere(string left, SqlBinaryOperator sqlOperator, string right);
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.
right
System.String
A SQL expression on the right of the operator.
Returns
TBuilder
Returns the TBuilder
object which can be used to add more search conditions to the current WHERE clause.
Examples
The following code example demonstrates how to use the OrWhere method to add an OR condition to the WHERE clause. In this example, the OR condition associates two tables using the operator "=".
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlWhereAndOrExamples
{
public class OrWhereExample
{
private readonly SchoolContext _context;
public OrWhereExample(SchoolContext dataContext)
{
// Sets data context.
_context = dataContext;
}
public void Example4()
{
// Declares SqlQueryBuilder.
var sqlbuilder = new SqlQueryBuilder();
// Defines a SQL statement, and adds an OR WHERE condition to associate two tables:
// a.DepartmentID equal to b.DepartmentID
sqlbuilder.Select(new string[] { "CourseID", "Title" })
.From("Course", "a")
.From("Department", "b")
.Where("CourseID", SqlBinaryOperator.GreaterThan,
SqlBuilder.Parameter<int>("courid"))
.OrWhere("a.DepartmentID", SqlBinaryOperator.Equals,
"b.DepartmentID");
string sql = sqlbuilder.ToSqlString(_context);
Console.WriteLine(sql);
/*This code produces the following output:
SELECT
[CourseID],
[Title]
FROM [Course] AS [a] ,
[Department] AS [b]
WHERE ([CourseID] > @courid
OR [a].[DepartmentID] = [b].[DepartmentID])
*/
}
}
}
Applies to
.NET Standard
2.x