SqlBuilder.Where(string left, ISqlBuilder sqlBuilder) Method
.NET Standard 2.x
Creates an ISqlWhereCondition
object which represents a search condition that can be used when building 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
public static ISqlWhereCondition 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.ISqlWhereCondition
Returns the ISqlWhereCondition
object which can be used to add more search conditions to the 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.SqlBuilderExamples
{
public class WhereExample
{
private SchoolContext _context;
public WhereExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example5()
{
var sqlquerybuilder = new SqlQueryBuilder();
// Defines a subquery.
var subsqlbuilder = new SqlQueryBuilder();
subsqlbuilder.Select("DepartmentID")
.From("Department")
.Where("Name", SqlBuilder.Parameter<string>("name"));
// Defines a WHERE condition.
var where = SqlBuilder.Where("DepartmentID", subsqlbuilder);
// Creates a SQL statement.
var query = sqlquerybuilder
.Select("*")
.From("Course")
.Where(where);
// Converts to raw SQL for the database corresponding to the data context.
string sql = query.ToSqlString(_context);
Console.WriteLine(sql);
/*This code example produces the following output:
SELECT
*
FROM [Course]
WHERE ( [DepartmentID] = (SELECT
[DepartmentID]
FROM [Department]
WHERE ([Name] = @name)))
*/
}
}
}
Applies to
.NET Standard
2.x