Class Check
- Namespace
- YndigoBlue.Velocity.Constraints
- Assembly
- YndigoBlue.Velocity.dll
Represents a check constraint that enforces domain integrity by limiting the values that can be placed in a column.
public class Check : Constraint, IEquatable<Constraint>, IComparable<Constraint>
- Inheritance
-
Check
- Implements
Remarks
Check constraints validate data based on logical expressions. They are evaluated when data is inserted or updated. Common uses include range checks, value lists, and complex business rules.
Examples
using (var manager = new Manager(connection))
{
var schema = manager.LoadSchema("myschema");
var table = schema["products"];
Column colPrice = table["price"];
Column colStatus = table["status"];
Column colQuantity = table["quantity"];
// Simple range check: price must be greater than zero
Check checkPrice = table.CreateCheckConstraint("ck_products_price", [
colPrice, new CheckOperator(CheckOperatorType.GreaterThan), new Literal<decimal>(0) ]);
// String value check: status must not be empty
Check checkStatus = table.CreateCheckConstraint("ck_products_status", [
colStatus, new CheckOperator(CheckOperatorType.NotEquals), new Literal<string>("") ]);
// Compound check: price < 10000 OR quantity < 500
Check checkCompound = table.CreateCheckConstraint("ck_products_compound", [
colPrice, new CheckOperator(CheckOperatorType.LessThan), new Literal<decimal>(10000),
new CheckOperator(CheckOperatorType.Or),
colQuantity, new CheckOperator(CheckOperatorType.LessThan), new Literal<int>(500) ]);
// Apply the constraints to the database
manager.CreateConstraint(checkPrice);
manager.CreateConstraint(checkStatus);
manager.CreateConstraint(checkCompound);
}
Properties
- CheckItems
Gets or sets the collection of check items that make up the check expression.
- ConstraintType
Gets the type of constraint (PrimaryKey, ForeignKey, Unique, Check, or Default).
- Definition
Gets or sets the check constraint definition as a string (used when loading from database).
Methods
- IsEqual(Constraint)
Always returns true. A check item is usually transformed by an RDBMS and impossible to reliably compare
- ToString()
Returns a string that represents the current object.