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
tableSqlTableBuilderCreated table.
AfterCreateView(SqlViewBuilder)
Callback invoked just after the view creation has been processed.
protected virtual void AfterCreateView(SqlViewBuilder view)
Parameters
viewSqlViewBuilderCreated 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
objSqlObjectBuilderExisting object to check.
oldPrimaryKeySqlPrimaryKeyBuilderPrimary key to replace.
Returns
- bool
true when
objisoldPrimaryKeyor 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
namestringName 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
tableSqlTableBuilderTable that this check is attached to.
namestringCheck's name.
conditionSqlConditionNodeUnderlying condition of this check constraint.
referencedColumnsReadOnlyArray<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
tableSqlTableBuilder
Returns
CreateForeignKeyBuilder(string, SqlIndexBuilder, SqlIndexBuilder)
Creates a new SqlForeignKeyBuilder instance.
protected abstract SqlForeignKeyBuilder CreateForeignKeyBuilder(string name, SqlIndexBuilder originIndex, SqlIndexBuilder referencedIndex)
Parameters
namestringForeign key's name.
originIndexSqlIndexBuilderSQL index that this foreign key originates from.
referencedIndexSqlIndexBuilderSQL 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
tableSqlTableBuilderTable that this index is attached to.
namestringIndex's name.
columnsSqlIndexBuilderColumns<SqlColumnBuilder>Collection of columns that define this index.
isUniqueboolSpecifies whether or not this index is unique.
referencedColumnsReadOnlyArray<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
tableSqlTableBuilder
Returns
CreatePrimaryKeyBuilder(string, SqlIndexBuilder)
Creates a new SqlPrimaryKeyBuilder instance.
protected abstract SqlPrimaryKeyBuilder CreatePrimaryKeyBuilder(string name, SqlIndexBuilder index)
Parameters
namestringPrimary key's name.
indexSqlIndexBuilderUnderlying index that defines this primary key.
Returns
- SqlPrimaryKeyBuilder
New SqlPrimaryKeyBuilder instance.
CreateTable(string)
Creates a new table builder.
public SqlTableBuilder CreateTable(string name)
Parameters
namestringName 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
namestringTable's name.
Returns
- SqlTableBuilder
New SqlTableBuilder instance
CreateView(string, SqlQueryExpressionNode)
Creates a new view builder.
public SqlViewBuilder CreateView(string name, SqlQueryExpressionNode source)
Parameters
namestringName of the view.
sourceSqlQueryExpressionNodeUnderlying 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
namestringView's name.
sourceSqlQueryExpressionNodeUnderlying source query expression that defines this view.
referencedObjectsReadOnlyArray<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
namestringName 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
namestringName 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
namestringName 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
namestringName 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
namestringName 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
namestringName 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
namestringName 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
namestringName 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
namestringName 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
tableSqlTableBuilderSqlTableBuilder that the foreign key belongs to.
originIndexSqlIndexBuilderSqlIndexBuilder from which the foreign key originates.
referencedIndexSqlIndexBuilderSqlIndexBuilder 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
tableSqlTableBuilderSqlTableBuilder that the index belongs to.
columnsSqlIndexBuilderColumns<SqlColumnBuilder>Collection of columns that belong to the index.
isUniqueboolSpecifies 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
tableSqlTableBuilderSqlTableBuilder that the primary key belongs to.
indexSqlIndexBuilderSqlIndexBuilder 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
namestringName 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
namestringName 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
namestringName 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
namestringName 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
namestringName 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
namestringName 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
namestringName of the view to return.
Returns
- SqlViewBuilder
Existing view or null when view does not exist.