Sql.Net Class Library Documentation

WhereClause Class

Describes the WHERE clause of a SELECT statement

For a list of all members of this type, see WhereClause Members.


public class WhereClause : ICloneable

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.


Using WhereClause you can abstractly define most common SQL conditional expressions. A WhereClause consists of individual terms and sub clauses. Between all terms and sub clauses of the same clause exists a single logical relationship. To create a group of terms with a different relationship, create a sub clause with the desired relationship and add it to the relevant SubClausescollection. Terms of a where clause are represnted by the WhereTerm class while the sub clauses are represnted by the same WhereClause class.


The following example attempts to demonstrate some of the most common usages of WhereClause and WhereTerm classes

FromTerm tCustomers = FromTerm.Table("customers", "c");
FromTerm tProducts = FromTerm.Table("products", "p");
FromTerm tOrders = FromTerm.Table("orders", "o");

SelectQuery query = new SelectQuery();

query.Columns.Add(new SelectColumn("name", tCustomers));
query.Columns.Add(new SelectColumn("name", tProducts));
query.Columns.Add(new SelectColumn("price", tProducts));

query.FromClause.BaseTable = tCustomers;
query.FromClause.Join(JoinType.Left, tCustomers, tOrders, "customerId", "customerId");
query.FromClause.Join(JoinType.Inner, tOrders, tProducts, "productId", "productId");
query.WherePhrase.Terms.Add(WhereTerm.CreateCompare(SqlExpression.Field("name", tCustomers), SqlExpression.String("John"), CompareOperator.Equal));
query.WherePhrase.Terms.Add(WhereTerm.CreateCompare(SqlExpression.Field("name", tCustomers), SqlExpression.String("J%"), CompareOperator.Like));
query.WherePhrase.Terms.Add(WhereTerm.CreateCompare(SqlExpression.Date(DateTime.Now), SqlExpression.Field("date", tOrders), CompareOperator.Greater));
query.WherePhrase.Terms.Add(WhereTerm.CreateCompare(SqlExpression.Number(1), SqlExpression.Number(1), CompareOperator.BitwiseAnd));
WhereClause group = new WhereClause(WhereClauseRelationship.Or);
group.Terms.Add(WhereTerm.CreateBetween(SqlExpression.Field("price", tProducts), SqlExpression.Number(1), SqlExpression.Number(10)));
group.Terms.Add(WhereTerm.CreateIn(SqlExpression.Field("name", tProducts), new string[] {"Nail", "Hamer", "Skrewdriver"}));



Namespace: Reeb.SqlOM

Assembly: Reeb.SqlOM (in Reeb.SqlOM.dll)

See Also

WhereClause Members | Reeb.SqlOM Namespace