Table of Contents

Class SqlObjectBuilderCollection

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

Represents a collection of SQL schema object builders.

public abstract class SqlObjectBuilderCollection : SqlBuilderApi, ISqlObjectBuilderCollection, IReadOnlyCollection<ISqlObjectBuilder>, IEnumerable<ISqlObjectBuilder>, IEnumerable
Inheritance
SqlObjectBuilderCollection
Implements
Derived
Inherited Members

Constructors

SqlObjectBuilderCollection()

Creates a new empty SqlObjectBuilderCollection instance.

protected SqlObjectBuilderCollection()

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

Schema

Schema that this collection belongs to.

public SqlSchemaBuilder Schema { get; }

Property Value

SqlSchemaBuilder

Methods

AfterCreateTable(SqlTableBuilder)

Callback invoked just after the table creation has been processed.

protected virtual void AfterCreateTable(SqlTableBuilder table)

Parameters

table SqlTableBuilder

Created table.

AfterCreateView(SqlViewBuilder)

Callback invoked just after the view creation has been processed.

protected virtual void AfterCreateView(SqlViewBuilder view)

Parameters

view SqlViewBuilder

Created view.

CanReplaceWithPrimaryKey(SqlObjectBuilder, SqlPrimaryKeyBuilder?)

Checks whether or not an existing object can be replaced with a new primary key.

[Pure]
protected static bool CanReplaceWithPrimaryKey(SqlObjectBuilder obj, SqlPrimaryKeyBuilder? oldPrimaryKey)

Parameters

obj SqlObjectBuilder

Existing object to check.

oldPrimaryKey SqlPrimaryKeyBuilder

Primary key to replace.

Returns

bool

true when obj is oldPrimaryKey or is and index with its primary key being oldPrimaryKey, otherwise false.

Contains(string)

Checks whether or not an object with the provided name exists.

[Pure]
public bool Contains(string name)

Parameters

name string

Name to check.

Returns

bool

true when object exists, otherwise false.

CreateCheckBuilder(SqlTableBuilder, string, SqlConditionNode, ReadOnlyArray<SqlColumnBuilder>)

Creates a new SqlCheckBuilder instance.

protected abstract SqlCheckBuilder CreateCheckBuilder(SqlTableBuilder table, string name, SqlConditionNode condition, ReadOnlyArray<SqlColumnBuilder> referencedColumns)

Parameters

table SqlTableBuilder

Table that this check is attached to.

name string

Check's name.

condition SqlConditionNode

Underlying condition of this check constraint.

referencedColumns ReadOnlyArray<SqlColumnBuilder>

Collection of columns referenced by this check constraint.

Returns

SqlCheckBuilder

New SqlCheckBuilder instance.

CreateCheckConditionValidator(SqlTableBuilder)

Creates a new SqlTableScopeExpressionValidator used for check constraint's Condition validation.

[Pure]
protected virtual SqlTableScopeExpressionValidator CreateCheckConditionValidator(SqlTableBuilder table)

Parameters

table SqlTableBuilder

Returns

SqlTableScopeExpressionValidator

New SqlTableScopeExpressionValidator instance.

CreateForeignKeyBuilder(string, SqlIndexBuilder, SqlIndexBuilder)

Creates a new SqlForeignKeyBuilder instance.

protected abstract SqlForeignKeyBuilder CreateForeignKeyBuilder(string name, SqlIndexBuilder originIndex, SqlIndexBuilder referencedIndex)

Parameters

name string

Foreign key's name.

originIndex SqlIndexBuilder

SQL index that this foreign key originates from.

referencedIndex SqlIndexBuilder

SQL index referenced by this foreign key.

Returns

SqlForeignKeyBuilder

New SqlForeignKeyBuilder instance.

CreateIndexBuilder(SqlTableBuilder, string, SqlIndexBuilderColumns<SqlColumnBuilder>, bool, ReadOnlyArray<SqlColumnBuilder>)

Creates a new SqlIndexBuilder instance.

protected abstract SqlIndexBuilder CreateIndexBuilder(SqlTableBuilder table, string name, SqlIndexBuilderColumns<SqlColumnBuilder> columns, bool isUnique, ReadOnlyArray<SqlColumnBuilder> referencedColumns)

Parameters

table SqlTableBuilder

Table that this index is attached to.

name string

Index's name.

columns SqlIndexBuilderColumns<SqlColumnBuilder>

Collection of columns that define this index.

isUnique bool

Specifies whether or not this index is unique.

referencedColumns ReadOnlyArray<SqlColumnBuilder>

Collection of columns referenced by this index's Columns.

Returns

SqlIndexBuilder

New SqlIndexBuilder instance.

CreateIndexColumnExpressionValidator(SqlTableBuilder)

Creates a new SqlTableScopeExpressionValidator used for index constraint's Columns expressions validation.

[Pure]
protected virtual SqlTableScopeExpressionValidator CreateIndexColumnExpressionValidator(SqlTableBuilder table)

Parameters

table SqlTableBuilder

Returns

SqlTableScopeExpressionValidator

New SqlTableScopeExpressionValidator instance.

CreatePrimaryKeyBuilder(string, SqlIndexBuilder)

Creates a new SqlPrimaryKeyBuilder instance.

protected abstract SqlPrimaryKeyBuilder CreatePrimaryKeyBuilder(string name, SqlIndexBuilder index)

Parameters

name string

Primary key's name.

index SqlIndexBuilder

Underlying index that defines this primary key.

Returns

SqlPrimaryKeyBuilder

New SqlPrimaryKeyBuilder instance.

CreateTable(string)

Creates a new table builder.

public SqlTableBuilder CreateTable(string name)

Parameters

name string

Name of the table.

Returns

SqlTableBuilder

New ISqlTableBuilder instance.

Exceptions

SqlObjectBuilderException

When table could not be created.

CreateTableBuilder(string)

Creates a new SqlTableBuilder instance.

protected abstract SqlTableBuilder CreateTableBuilder(string name)

Parameters

name string

Table's name.

Returns

SqlTableBuilder

New SqlTableBuilder instance

CreateView(string, SqlQueryExpressionNode)

Creates a new view builder.

public SqlViewBuilder CreateView(string name, SqlQueryExpressionNode source)

Parameters

name string

Name of the view.

source SqlQueryExpressionNode

Underlying source query expression that defines the view.

Returns

SqlViewBuilder

New ISqlViewBuilder instance.

Exceptions

SqlObjectBuilderException

When view could not be created.

CreateViewBuilder(string, SqlQueryExpressionNode, ReadOnlyArray<SqlObjectBuilder>)

Creates a new SqlViewBuilder instance.

protected abstract SqlViewBuilder CreateViewBuilder(string name, SqlQueryExpressionNode source, ReadOnlyArray<SqlObjectBuilder> referencedObjects)

Parameters

name string

View's name.

source SqlQueryExpressionNode

Underlying source query expression that defines this view.

referencedObjects ReadOnlyArray<SqlObjectBuilder>

Collection of objects (tables, views and columns) referenced by this view's Source.

Returns

SqlViewBuilder

New SqlViewBuilder instance

CreateViewSourceValidator()

Creates a new SqlSchemaScopeExpressionValidator used for view's Source validation.

[Pure]
protected virtual SqlSchemaScopeExpressionValidator CreateViewSourceValidator()

Returns

SqlSchemaScopeExpressionValidator

New SqlSchemaScopeExpressionValidator instance.

Get(string)

Returns an object with the provided name.

[Pure]
public SqlObjectBuilder Get(string name)

Parameters

name string

Name of the object to return.

Returns

SqlObjectBuilder

Existing object.

Exceptions

KeyNotFoundException

When object 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 object exists but is not a check.

GetEnumerator()

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

[Pure]
public SqlObjectBuilderEnumerator<SqlObjectBuilder> GetEnumerator()

Returns

SqlObjectBuilderEnumerator<SqlObjectBuilder>

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 object 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 object exists but is not an index.

GetOrCreateTable(string)

Creates a new table builder or returns an existing table builder.

public SqlTableBuilder GetOrCreateTable(string name)

Parameters

name string

Name of the table.

Returns

SqlTableBuilder

New ISqlTableBuilder instance or an existing table builder.

Exceptions

SqlObjectBuilderException

When table does not exist and could not be created.

GetPrimaryKey(string)

Returns a primary key with the provided name.

[Pure]
public SqlPrimaryKeyBuilder GetPrimaryKey(string name)

Parameters

name string

Name of the primary key to return.

Returns

SqlPrimaryKeyBuilder

Existing primary key.

Exceptions

KeyNotFoundException

When primary key does not exist.

SqlObjectCastException

When object exists but is not a primary key.

GetTable(string)

Returns a table with the provided name.

[Pure]
public SqlTableBuilder GetTable(string name)

Parameters

name string

Name of the table to return.

Returns

SqlTableBuilder

Existing table.

Exceptions

KeyNotFoundException

When table does not exist.

SqlObjectCastException

When object exists but is not a table.

GetView(string)

Returns a view with the provided name.

[Pure]
public SqlViewBuilder GetView(string name)

Parameters

name string

Name of the view to return.

Returns

SqlViewBuilder

Existing view.

Exceptions

KeyNotFoundException

When view does not exist.

SqlObjectCastException

When object exists but is not a view.

Remove(string)

Attempts to remove an object by its name.

public bool Remove(string name)

Parameters

name string

Name of the object to remove.

Returns

bool

true when object was removed, otherwise false.

ThrowIfForeignKeyIsInvalid(SqlTableBuilder, SqlIndexBuilder, SqlIndexBuilder)

Throws an exception when a foreign key is not valid.

protected virtual void ThrowIfForeignKeyIsInvalid(SqlTableBuilder table, SqlIndexBuilder originIndex, SqlIndexBuilder referencedIndex)

Parameters

table SqlTableBuilder

SqlTableBuilder that the foreign key belongs to.

originIndex SqlIndexBuilder

SqlIndexBuilder from which the foreign key originates.

referencedIndex SqlIndexBuilder

SqlIndexBuilder which the foreign key references.

Remarks

Exceptions

SqlObjectBuilderException

When foreign key is not considered valid.

ThrowIfIndexColumnsAreInvalid(SqlTableBuilder, SqlIndexBuilderColumns<SqlColumnBuilder>, bool)

Throws an exception when an index's columns are not valid.

protected virtual void ThrowIfIndexColumnsAreInvalid(SqlTableBuilder table, SqlIndexBuilderColumns<SqlColumnBuilder> columns, bool isUnique)

Parameters

table SqlTableBuilder

SqlTableBuilder that the index belongs to.

columns SqlIndexBuilderColumns<SqlColumnBuilder>

Collection of columns that belong to the index.

isUnique bool

Specifies whether or not the index is unique.

Remarks

Exceptions

SqlObjectBuilderException

When index columns are not considered valid.

ThrowIfPrimaryKeyIsInvalid(SqlTableBuilder, SqlIndexBuilder)

Throws an exception when a primary key is not valid.

protected virtual void ThrowIfPrimaryKeyIsInvalid(SqlTableBuilder table, SqlIndexBuilder index)

Parameters

table SqlTableBuilder

SqlTableBuilder that the primary key belongs to.

index SqlIndexBuilder

SqlIndexBuilder that is the underlying index of the primary key.

Remarks

Exceptions

SqlObjectBuilderException

When primary key is not considered valid.

TryGet(string)

Attempts to return an object with the provided name.

[Pure]
public SqlObjectBuilder? TryGet(string name)

Parameters

name string

Name of the object to return.

Returns

SqlObjectBuilder

Existing object or null when object 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(string)

Attempts to return a primary key with the provided name.

[Pure]
public SqlPrimaryKeyBuilder? TryGetPrimaryKey(string name)

Parameters

name string

Name of the primary key to return.

Returns

SqlPrimaryKeyBuilder

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

TryGetTable(string)

Attempts to return a table with the provided name.

[Pure]
public SqlTableBuilder? TryGetTable(string name)

Parameters

name string

Name of the table to return.

Returns

SqlTableBuilder

Existing table or null when table does not exist.

TryGetView(string)

Attempts to return a view with the provided name.

[Pure]
public SqlViewBuilder? TryGetView(string name)

Parameters

name string

Name of the view to return.

Returns

SqlViewBuilder

Existing view or null when view does not exist.