Table of Contents

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

T

The 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):

  1. Cannot mix inner and outer query column references in the same criterion
  2. Cannot mix columns and literal values in the same criterion
  3. 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

Criterion(ISelectItem, ConditionalType)
Criterion(ISelectItem, ConditionalType, IEnumerable<T>)
Criterion(ISelectItem, ConditionalType, IEnumerable<T>, Query)
Criterion(ISelectItem, ConditionalType, T)
Criterion(ISelectItem, ConditionalType, T, Query)
Criterion(ISelectItem, T)
Criterion(ISelectItem, T, Query)
Criterion(T)
Criterion(T, Query)

Properties

DataType

Gets the data type of the comparison values.

FilterItemType

Gets the type of filter item.

HasSelectItem
this[string]
OperatorType

Gets the comparison operator type (equals, less than, IN, etc.).

OuterQuery
ParameterNames

Gets the names of parameters used for comparison values.

SelectItem

Gets the select item (column or expression) being filtered.

Value
ValueFromOuterQuery
Values

Methods

AddValue(T)