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
// Define a table with check constraints
var table = new Table(schema, "products");
table.AddColumn("id", DataType.Integer, autoIncrement: true);
table.AddColumn("name", DataType.VarChar, 100);
table.AddColumn("price", DataType.Decimal);
table.AddColumn("quantity", DataType.Integer);
table.AddColumn("status", DataType.VarChar, 20);
// Create check constraint ensuring price is positive
var checkPrice = new Check("ck_products_price", schema.Name, "products",
new ICheckItem[] {
table["price"],
new CheckOperator(CheckOperatorType.GreaterThan),
new Literal<decimal>(0)
});
// Create check constraint for valid status values
var checkStatus = new Check("ck_products_status", schema.Name, "products",
new ICheckItem[] {
table["status"],
new CheckOperator(CheckOperatorType.In),
new Literal<string>("Active,Inactive,Discontinued")
});
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.