Table of Contents

Class SqlConstraintBuilderCollection

Namespace
LfrlAnvil.Sql.Objects.Builders
Assembly
LfrlAnvil.Sql.Core.dll

Represents a collection of SQL table constraint builders.

public abstract class SqlConstraintBuilderCollection : SqlBuilderApi, ISqlConstraintBuilderCollection, IReadOnlyCollection<ISqlConstraintBuilder>, IEnumerable<ISqlConstraintBuilder>, IEnumerable
Inheritance
SqlConstraintBuilderCollection
Implements
Derived
Inherited Members
Extension Methods

Constructors

SqlConstraintBuilderCollection()

Creates a new empty SqlConstraintBuilderCollection instance.

protected SqlConstraintBuilderCollection()

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

Table

Table that this collection belongs to.

public SqlTableBuilder Table { get; }

Property Value

SqlTableBuilder

Methods

AfterCreateCheck(SqlCheckBuilder)

Callback invoked just after the check creation has been processed.

protected virtual void AfterCreateCheck(SqlCheckBuilder check)

Parameters

check SqlCheckBuilder

Created check.

AfterCreateForeignKey(SqlForeignKeyBuilder)

Callback invoked just after the foreignKey creation has been processed.

protected virtual void AfterCreateForeignKey(SqlForeignKeyBuilder foreignKey)

Parameters

foreignKey SqlForeignKeyBuilder

Created foreign key.

AfterCreateIndex(SqlIndexBuilder)

Callback invoked just after the index creation has been processed.

protected virtual void AfterCreateIndex(SqlIndexBuilder index)

Parameters

index SqlIndexBuilder

Created index.

AfterCreatePrimaryKey(SqlPrimaryKeyBuilder)

Callback invoked just after the primaryKey creation has been processed.

protected virtual void AfterCreatePrimaryKey(SqlPrimaryKeyBuilder primaryKey)

Parameters

primaryKey SqlPrimaryKeyBuilder

Created primary key.

Contains(string)

Checks whether or not a constraint with the provided name exists.

[Pure]
public bool Contains(string name)

Parameters

name string

Name to check.

Returns

bool

true when constraint exists, otherwise false.

CreateCheck(SqlConditionNode)

Creates a new check builder with a default name.

public SqlCheckBuilder CreateCheck(SqlConditionNode condition)

Parameters

condition SqlConditionNode

Underlying condition of the check constraint.

Returns

SqlCheckBuilder

New ISqlCheckBuilder instance.

Exceptions

SqlObjectBuilderException

When check constraint could not be created.

CreateCheck(string, SqlConditionNode)

Creates a new check builder.

public SqlCheckBuilder CreateCheck(string name, SqlConditionNode condition)

Parameters

name string

Name of the check constraint.

condition SqlConditionNode

Underlying condition of the check constraint.

Returns

SqlCheckBuilder

New ISqlCheckBuilder instance.

Exceptions

SqlObjectBuilderException

When check constraint could not be created.

CreateForeignKey(SqlIndexBuilder, SqlIndexBuilder)

Creates a new foreign key builder with a default name.

public SqlForeignKeyBuilder CreateForeignKey(SqlIndexBuilder originIndex, SqlIndexBuilder referencedIndex)

Parameters

originIndex SqlIndexBuilder

SQL index that the foreign key originates from.

referencedIndex SqlIndexBuilder

SQL index referenced by the foreign key.

Returns

SqlForeignKeyBuilder

New ISqlForeignKeyBuilder instance.

Exceptions

SqlObjectBuilderException

When foreign key constraint could not be created.

CreateForeignKey(string, SqlIndexBuilder, SqlIndexBuilder)

Creates a new foreign key builder.

public SqlForeignKeyBuilder CreateForeignKey(string name, SqlIndexBuilder originIndex, SqlIndexBuilder referencedIndex)

Parameters

name string

Name of the foreign key constraint.

originIndex SqlIndexBuilder

SQL index that the foreign key originates from.

referencedIndex SqlIndexBuilder

SQL index referenced by the foreign key.

Returns

SqlForeignKeyBuilder

New ISqlForeignKeyBuilder instance.

Exceptions

SqlObjectBuilderException

When foreign key constraint could not be created.

CreateIndex(ReadOnlyArray<SqlOrderByNode>, bool)

Creates a new index builder with a default name.

public SqlIndexBuilder CreateIndex(ReadOnlyArray<SqlOrderByNode> columns, bool isUnique = false)

Parameters

columns ReadOnlyArray<SqlOrderByNode>

Collection of columns that define the index.

isUnique bool

Specifies whether or not the index should start as unique. Equal to false by default.

Returns

SqlIndexBuilder

New ISqlIndexBuilder instance.

Exceptions

SqlObjectBuilderException

When index constraint could not be created.

CreateIndex(string, ReadOnlyArray<SqlOrderByNode>, bool)

Creates a new index builder.

public SqlIndexBuilder CreateIndex(string name, ReadOnlyArray<SqlOrderByNode> columns, bool isUnique = false)

Parameters

name string

Name of the index constraint.

columns ReadOnlyArray<SqlOrderByNode>

Collection of columns that define the index.

isUnique bool

Specifies whether or not the index should start as unique. Equal to false by default.

Returns

SqlIndexBuilder

New ISqlIndexBuilder instance.

Exceptions

SqlObjectBuilderException

When index constraint could not be created.

Get(string)

Returns a constraint with the provided name.

[Pure]
public SqlConstraintBuilder Get(string name)

Parameters

name string

Name of the constraint to return.

Returns

SqlConstraintBuilder

Existing constraint.

Exceptions

KeyNotFoundException

When constraint does not exist.

GetCheck(string)

Returns a check with the provided name.

[Pure]
public SqlCheckBuilder GetCheck(string name)

Parameters

name string

Name of the check to return.

Returns

SqlCheckBuilder

Existing check.

Exceptions

KeyNotFoundException

When check does not exist.

SqlObjectCastException

When constraint exists but is not a check.

GetEnumerator()

Creates a new SqlObjectBuilderEnumerator<T> instance for this collection.

[Pure]
public SqlObjectBuilderEnumerator<SqlConstraintBuilder> GetEnumerator()

Returns

SqlObjectBuilderEnumerator<SqlConstraintBuilder>

New SqlObjectBuilderEnumerator<T> instance.

GetForeignKey(string)

Returns a foreign key with the provided name.

[Pure]
public SqlForeignKeyBuilder GetForeignKey(string name)

Parameters

name string

Name of the foreign key to return.

Returns

SqlForeignKeyBuilder

Existing foreign key.

Exceptions

KeyNotFoundException

When foreign key does not exist.

SqlObjectCastException

When constraint exists but is not a foreign key.

GetIndex(string)

Returns an index with the provided name.

[Pure]
public SqlIndexBuilder GetIndex(string name)

Parameters

name string

Name of the index to return.

Returns

SqlIndexBuilder

Existing index.

Exceptions

KeyNotFoundException

When index does not exist.

SqlObjectCastException

When constraint exists but is not an index.

GetPrimaryKey()

Retrieves a primary key builder.

[Pure]
public SqlPrimaryKeyBuilder GetPrimaryKey()

Returns

SqlPrimaryKeyBuilder

Existing primary key builder.

Exceptions

SqlObjectBuilderException

When primary key builder does not exist.

Remove(string)

Attempts to remove a constraint by its name.

public bool Remove(string name)

Parameters

name string

Name of the constraint to remove.

Returns

bool

true when constraint was removed, otherwise false.

SetPrimaryKey(SqlIndexBuilder)

Sets a new primary key builder with a default name.

public SqlPrimaryKeyBuilder SetPrimaryKey(SqlIndexBuilder index)

Parameters

index SqlIndexBuilder

Underlying index that defines the primary key.

Returns

SqlPrimaryKeyBuilder

New ISqlPrimaryKeyBuilder instance.

Exceptions

SqlObjectBuilderException

When primary key constraint could not be created.

SetPrimaryKey(string, SqlIndexBuilder)

Sets a new primary key builder.

public SqlPrimaryKeyBuilder SetPrimaryKey(string name, SqlIndexBuilder index)

Parameters

name string

Name of the primary key constraint.

index SqlIndexBuilder

Underlying index that defines the primary key.

Returns

SqlPrimaryKeyBuilder

New ISqlPrimaryKeyBuilder instance.

Exceptions

SqlObjectBuilderException

When primary key constraint could not be created.

TryGet(string)

Attempts to return a constraint with the provided name.

[Pure]
public SqlConstraintBuilder? TryGet(string name)

Parameters

name string

Name of the constraint to return.

Returns

SqlConstraintBuilder

Existing constraint or null when constraint does not exist.

TryGetCheck(string)

Attempts to return a check with the provided name.

[Pure]
public SqlCheckBuilder? TryGetCheck(string name)

Parameters

name string

Name of the check to return.

Returns

SqlCheckBuilder

Existing check or null when check does not exist.

TryGetForeignKey(string)

Attempts to return a foreign key with the provided name.

[Pure]
public SqlForeignKeyBuilder? TryGetForeignKey(string name)

Parameters

name string

Name of the foreign key to return.

Returns

SqlForeignKeyBuilder

Existing foreign key or null when foreign key does not exist.

TryGetIndex(string)

Attempts to return an index with the provided name.

[Pure]
public SqlIndexBuilder? TryGetIndex(string name)

Parameters

name string

Name of the index to return.

Returns

SqlIndexBuilder

Existing index or null when index does not exist.

TryGetPrimaryKey()

Attempts to retrieve a primary key builder.

[Pure]
public SqlPrimaryKeyBuilder? TryGetPrimaryKey()

Returns

SqlPrimaryKeyBuilder

Existing primary key builder or null when it does not exist.