Table of Contents

Method CreateConstraint

Namespace
YndigoBlue.Velocity.Engine
Assembly
YndigoBlue.Velocity.dll

CreateConstraint(Constraint)

Creates a constraint (primary key, foreign key, unique, check, or default) on an existing table.

public void CreateConstraint(Constraint constraint)

Parameters

constraint Constraint

The Constraint object to create (e.g., PrimaryKey, ForeignKey, Unique).

Examples

using (var m = new Manager(conn))
{
    var schema = m.LoadSchema("app");
    var ordersTable = schema["orders"];
    var customersTable = schema["customers"];

    // Create a foreign key constraint
    var fk = new ForeignKey("fk_customer", ordersTable, customersTable);
    fk.AddColumnPair(ordersTable["customer_id"], customersTable["id"]);
    m.CreateConstraint(fk);
}

Exceptions

DbException

Thrown when a database error occurs.