Class SqlObjectBuilderCollection
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
Methods
AfterCreateTable(SqlTableBuilder)
Callback invoked just after the table
creation has been processed.
protected virtual void AfterCreateTable(SqlTableBuilder table)
Parameters
table
SqlTableBuilderCreated table.
AfterCreateView(SqlViewBuilder)
Callback invoked just after the view
creation has been processed.
protected virtual void AfterCreateView(SqlViewBuilder view)
Parameters
view
SqlViewBuilderCreated 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
SqlObjectBuilderExisting object to check.
oldPrimaryKey
SqlPrimaryKeyBuilderPrimary key to replace.
Returns
- bool
true when
obj
isoldPrimaryKey
or is and index with its primary key beingoldPrimaryKey
, otherwise false.
Contains(string)
Checks whether or not an object with the provided name
exists.
[Pure]
public bool Contains(string name)
Parameters
name
stringName 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
SqlTableBuilderTable that this check is attached to.
name
stringCheck's name.
condition
SqlConditionNodeUnderlying 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
CreateForeignKeyBuilder(string, SqlIndexBuilder, SqlIndexBuilder)
Creates a new SqlForeignKeyBuilder instance.
protected abstract SqlForeignKeyBuilder CreateForeignKeyBuilder(string name, SqlIndexBuilder originIndex, SqlIndexBuilder referencedIndex)
Parameters
name
stringForeign key's name.
originIndex
SqlIndexBuilderSQL index that this foreign key originates from.
referencedIndex
SqlIndexBuilderSQL 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
SqlTableBuilderTable that this index is attached to.
name
stringIndex's name.
columns
SqlIndexBuilderColumns<SqlColumnBuilder>Collection of columns that define this index.
isUnique
boolSpecifies 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
CreatePrimaryKeyBuilder(string, SqlIndexBuilder)
Creates a new SqlPrimaryKeyBuilder instance.
protected abstract SqlPrimaryKeyBuilder CreatePrimaryKeyBuilder(string name, SqlIndexBuilder index)
Parameters
name
stringPrimary key's name.
index
SqlIndexBuilderUnderlying 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
stringName 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
stringTable's name.
Returns
- SqlTableBuilder
New SqlTableBuilder instance
CreateView(string, SqlQueryExpressionNode)
Creates a new view builder.
public SqlViewBuilder CreateView(string name, SqlQueryExpressionNode source)
Parameters
name
stringName of the view.
source
SqlQueryExpressionNodeUnderlying 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
stringView's name.
source
SqlQueryExpressionNodeUnderlying 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
Get(string)
Returns an object with the provided name
.
[Pure]
public SqlObjectBuilder Get(string name)
Parameters
name
stringName 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
stringName 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
GetForeignKey(string)
Returns a foreign key with the provided name
.
[Pure]
public SqlForeignKeyBuilder GetForeignKey(string name)
Parameters
name
stringName 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
stringName 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
stringName 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
stringName 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
stringName 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
stringName 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
stringName 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
SqlTableBuilderSqlTableBuilder that the foreign key belongs to.
originIndex
SqlIndexBuilderSqlIndexBuilder from which the foreign key originates.
referencedIndex
SqlIndexBuilderSqlIndexBuilder which the foreign key references.
Remarks
See AssertForeignKey(SqlTableBuilder, SqlIndexBuilder, SqlIndexBuilder) for more information.
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
SqlTableBuilderSqlTableBuilder that the index belongs to.
columns
SqlIndexBuilderColumns<SqlColumnBuilder>Collection of columns that belong to the index.
isUnique
boolSpecifies whether or not the index is unique.
Remarks
See AssertIndexColumns(SqlTableBuilder, SqlIndexBuilderColumns<SqlColumnBuilder>, bool) for more information.
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
SqlTableBuilderSqlTableBuilder that the primary key belongs to.
index
SqlIndexBuilderSqlIndexBuilder that is the underlying index of the primary key.
Remarks
See AssertPrimaryKey(SqlTableBuilder, SqlIndexBuilder) for more information.
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
stringName 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
stringName 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
stringName 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
stringName 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
stringName 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
stringName 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
stringName of the view to return.
Returns
- SqlViewBuilder
Existing view or null when view does not exist.