ISqlWhereBuilder.Where(ISqlWhereCondition condition) Method
.NET Standard 2.x
Creates a WHERE clause, and adds a search condition to the WHERE clause by an ISqlWhereCondition
object.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlWhereAndOr Where(ISqlWhereCondition condition);
Parameters
condition
SnapObjects.Data.ISqlWhereCondition
An ISqlWhereCondition
which represents a search condition in the WHERE clause.
This object can be created by using the SqlBuilder.Where
method and so on.
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 declares an ISqlWhereCondition object and then uses it in the Where method.
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 Example7()
{
// Declares SqlQueryBuilder.
ISqlQueryBuilder sqlQueryBuilder = new SqlQueryBuilder();
// Defines a WHERE condition.
ISqlWhereCondition where =
SqlBuilder.Where("DepartmentID", SqlBuilder.Parameter<int>("id"));
// Defines a query parameter and specifies the columns to select.
int deptid = 1;
string[] columns = { "CourseID", "Title" };
// Defines a SQL statement, and specifies to use the WHERE condition defined above.
sqlQueryBuilder.Select(columns)
.From("Course", "a")
.Where(where);
// Shows the SQL statement.
Console.WriteLine("The SQL statement: \n{0}",
sqlQueryBuilder.ToSqlString(_context));
// Executes the SQL statement.
var courses = _context.SqlExecutor
.Select<DynamicModel>(sqlQueryBuilder, deptid);
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 ([DepartmentID] = @id)
Title (first row) : Chemistry.
*/
}
}
}
Applies to
.NET Standard
2.x