Class Criterion<T>
- Namespace
- YndigoBlue.Velocity.Model
- Assembly
- YndigoBlue.Velocity.dll
Represents a single comparison criterion in a WHERE or HAVING clause.
public class Criterion<T> : IFilterItem, ICriterion
Type Parameters
TThe data type of the value being compared. Common types include: string, int, long, decimal, DateTime, bool, Query (for subqueries), Column (for column comparisons).
- Inheritance
-
Criterion<T>
- Implements
Examples
Simple equality:
// WHERE firstname = 'John'
Criterion<string> criterion = new Criterion<string>(
usersTable["firstname"],
ConditionalType.Equals,
"John"
);
Comparison operators:
// WHERE age > 30
Criterion<int> ageCriterion = new Criterion<int>(
usersTable["age"],
ConditionalType.GreaterThan,
30
);
IN clause with multiple values:
// WHERE status IN ('active', 'pending', 'approved')
List<string> statusValues = new List<string> { "active", "pending", "approved" };
Criterion<string> statusCriterion = new Criterion<string>(
usersTable["status"],
ConditionalType.In,
statusValues
);
BETWEEN clause:
// WHERE age BETWEEN 18 AND 65
List<int> ageRange = new List<int> { 18, 65 };
Criterion<int> ageCriterion = new Criterion<int>(
usersTable["age"],
ConditionalType.Between,
ageRange
);
Subquery criterion:
// WHERE age > (SELECT AVG(age) FROM users)
Query avgAgeQuery = new Query();
avgAgeQuery.AddFromItem(usersTable);
avgAgeQuery.AddSelectItem(new Function(FunctionType.Avg, usersTable["age"]));
Criterion<Query> ageCriterion = new Criterion<Query>(
usersTable["age"],
ConditionalType.GreaterThan,
avgAgeQuery
);
NULL checks:
// WHERE deleted_at IS NULL
Criterion<object> nullCriterion = new Criterion<object>(
usersTable["deleted_at"],
ConditionalType.IsNull
);
Remarks
Criterion is the fundamental building block for query filters. Each criterion represents a single comparison operation such as "age > 30" or "status = 'active'".
The generic type parameter determines the comparison value type:
- Criterion<string> - For text comparisons (VarChar, Char, Clob columns)
- Criterion<int>, Criterion<long>, Criterion<decimal> - For numeric comparisons
- Criterion<DateTime> - For date/time comparisons
- Criterion<bool> - For boolean comparisons
- Criterion<Query> - For subquery comparisons (IN, EXISTS, > subquery, etc.)
- Criterion<Column> - For column-to-column comparisons
Limitations when comparing columns (not literals):
- Cannot mix inner and outer query column references in the same criterion
- Cannot mix columns and literal values in the same criterion
- Can only reference one outer query at a time
These restrictions mean the following are not supported:
- WHERE x BETWEEN outer_table.col AND inner_table.col
- WHERE x BETWEEN column_value AND literal_value
- WHERE x IN (1, 2, 3, column_value)
Constructors
Properties
- DataType
Gets the data type of the comparison values.
- FilterItemType
Gets the type of filter item.
- OperatorType
Gets the comparison operator type (equals, less than, IN, etc.).
- ParameterNames
Gets the names of parameters used for comparison values.
- SelectItem
Gets the select item (column or expression) being filtered.