ISqlWhereBuilder.Where(string left, SqlBinaryOperator sqlOperator, ISqlParameter parameter) 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 parameter on the right of the operator.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlWhereAndOr Where(string left, SqlBinaryOperator sqlOperator, ISqlParameter parameter);
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.
parameter
SnapObjects.Data.ISqlParameter
An ISqlParameter
object which represents a SQL parameter on the right of the operator.
It can be created by calling the SqlBuilder.Parameter method.
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 the column value to equal to an input parameter.
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 Example4()
{
// Declares SqlQueryBuilder.
ISqlQueryBuilder sqlQueryBuilder = new SqlQueryBuilder();
// Specifies to use the SqlBinaryOperator.Equals operator for matching the values.
sqlQueryBuilder.Select("Title")
.From("Course")
.Where("CourseID",
SqlBinaryOperator.Equals,
SqlBuilder.Parameter<int>("courid"));
// Shows the SQL statement.
Console.WriteLine("The SQL statement: \n{0}",
sqlQueryBuilder.ToSqlString(_context));
// Executes the SQL statement.
int courid = 1050;
var title = _context.SqlExecutor.Scalar<string>(sqlQueryBuilder,
courid);
Console.WriteLine();
Console.WriteLine("Title : {0}.", title);
/*This code produces the following output:
The SQL statement:
SELECT
[Title]
FROM [Course]
WHERE ([CourseID] = @courid)
Title : Chemistry.
*/
}
}
}
Applies to
.NET Standard
2.x