ISqlWhereAndOr<TBuilder>.AndWhereValue(string left, SqlBinaryOperator sqlOperator, object value) Method
.NET Standard 2.x
Adds the AND
logical operator and a search condition to the WHERE clause; and specifies a SQL expression on the left of the operator and a specific value on the right of the operator.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
TBuilder AndWhereValue(string left, SqlBinaryOperator sqlOperator, object value);
Parameters
left
System.String
An expression on the left of the operator.
SqlBinaryOperator
SnapObjects.Data.SqlBinaryOperator
An enumeration value of SqlBinaryOperator
, which is the operator to test the expression on the left and the value on the right.
value
System.Object
The specific value 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 AndWhereValue method to add an AND condition to the WHERE clause. In this example, the AND condition specifies that the Title value must start with "C" (specified using a LIKE operator).
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlWhereAndOrExamples
{
public class AndWhereValueExample
{
private readonly SchoolContext _context;
public AndWhereValueExample(SchoolContext dataContext)
{
// Sets data context.
_context = dataContext;
}
public void Example2()
{
// Declares SqlQueryBuilder.
var sqlbuilder = new SqlQueryBuilder();
// Defines a SQL statement and adds an AND WHERE condition: Title like 'C%'.
sqlbuilder.Select("*")
.From("Course")
.Where("CourseID", SqlBinaryOperator.GreaterThan,
SqlBuilder.Parameter<int>("courid"))
.AndWhereValue("Title", SqlBinaryOperator.Like, "C%");
string sql = sqlbuilder.ToSqlString(_context);
Console.WriteLine(sql);
/*This code produces the following output:
SELECT
*
FROM [Course]
WHERE ([CourseID] > @courid
AND [Title] LIKE N'C%')
*/
}
}
}
Applies to
.NET Standard
2.x