ISqlWhereBuilder.Where(string left, ISqlBuilder sqlBuilder) Method
.NET Standard 2.x
Creates a WHERE clause, and adds a search condition to the WHERE clause. Specifies a SQL expression on the left of the operator and a SQL subquery on the right. The operator is '='.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlWhereAndOr Where(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.ISqlWhereAndOr
Returns the ISqlWhereAndOr
object which can be used to add more search conditions to the current WHERE clause.
Examples
The following code example uses the Where method to specify to match the column value with the result set of a SQL subquery.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlWhereBuilderExamples
{
public class WhereExample
{
private readonly SchoolContext _context;
public WhereExample(SchoolContext dataContext)
{
// Sets data context.
_context = dataContext;
}
public void Example5()
{
// Declares SqlQueryBuilder.
ISqlQueryBuilder sqlQueryBuilder = new SqlQueryBuilder();
// Defines a subquery.
ISqlQueryBuilder deptSubQuery = new SqlQueryBuilder();
deptSubQuery.Select("DepartmentID")
.From("Department")
.Where("Name", SqlBuilder.Parameter<string>("deptName"));
// Specifies the columns to select
string[] columns = { "CourseID", "Title" };
// Defines a SQL statement, and specifies the WHERE condition:
// the DepartmentID value equal to the result set of a subquery.
sqlQueryBuilder.Select(columns)
.From("Course", "a")
.Where("a.DepartmentID", deptSubQuery);
// Shows the SQL statement.
Console.WriteLine("The SQL statement: \n{0}",
sqlQueryBuilder.ToSqlString(_context));
// Executes the SQL statement.
string deptname = "Engineering";
var courses =
_context.SqlExecutor.Select<DynamicModel>(sqlQueryBuilder, deptname);
Console.WriteLine();
Console.WriteLine("Title (first row) : {0}.",
courses[0].GetValue("Title"));
/*This code produces the following output:
The SQL statement:
SELECT
[CourseID],
[Title]
FROM [Course] AS [a]
WHERE ( [a].[DepartmentID] = (SELECT
[DepartmentID]
FROM [Department]
WHERE ([Name] = @deptName)))
Title (first row) : Chemistry.
*/
}
}
}
Applies to
.NET Standard
2.x