Table of Contents

Class SqlObjectCollection

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

Represents a collection of SQL schema objects.

public abstract class SqlObjectCollection : ISqlObjectCollection, IReadOnlyCollection<ISqlObject>, IEnumerable<ISqlObject>, IEnumerable
Inheritance
SqlObjectCollection
Implements
Derived
Inherited Members

Constructors

SqlObjectCollection(SqlObjectBuilderCollection)

Creates a new SqlObjectCollection instance.

protected SqlObjectCollection(SqlObjectBuilderCollection source)

Parameters

source SqlObjectBuilderCollection

Source collection.

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 SqlSchema Schema { get; }

Property Value

SqlSchema

Methods

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.

CreateCheck(SqlTable, SqlCheckBuilder)

Creates a new SqlCheck instance.

[Pure]
protected abstract SqlCheck CreateCheck(SqlTable table, SqlCheckBuilder builder)

Parameters

table SqlTable

Table that this check constraint is attached to.

builder SqlCheckBuilder

Source check builder.

Returns

SqlCheck

New SqlCheck instance.

CreateForeignKey(SqlIndex, SqlIndex, SqlForeignKeyBuilder)

Creates a new SqlForeignKey instance.

[Pure]
protected abstract SqlForeignKey CreateForeignKey(SqlIndex originIndex, SqlIndex referencedIndex, SqlForeignKeyBuilder builder)

Parameters

originIndex SqlIndex

SQL index that this foreign key originates from.

referencedIndex SqlIndex

SQL index referenced by this foreign key.

builder SqlForeignKeyBuilder

Source foreign key builder.

Returns

SqlForeignKey

New SqlForeignKey instance.

CreateIndex(SqlTable, SqlIndexBuilder)

Creates a new SqlIndex instance.

[Pure]
protected abstract SqlIndex CreateIndex(SqlTable table, SqlIndexBuilder builder)

Parameters

table SqlTable

Table that this index belongs to.

builder SqlIndexBuilder

Source index builder.

Returns

SqlIndex

New SqlIndex instance.

CreatePrimaryKey(SqlIndex, SqlPrimaryKeyBuilder)

Creates a new SqlPrimaryKey instance.

[Pure]
protected abstract SqlPrimaryKey CreatePrimaryKey(SqlIndex index, SqlPrimaryKeyBuilder builder)

Parameters

index SqlIndex

Underlying index that defines this primary key.

builder SqlPrimaryKeyBuilder

Source primary key builder.

Returns

SqlPrimaryKey

New SqlPrimaryKey instance.

CreateTable(SqlTableBuilder)

Creates a new SqlTable instance.

[Pure]
protected abstract SqlTable CreateTable(SqlTableBuilder builder)

Parameters

builder SqlTableBuilder

Source table builder.

Returns

SqlTable

New SqlTable instance.

CreateUnknown(SqlObjectBuilder)

Creates a new UnknownSqlObject instance.

[Pure]
protected virtual SqlObject CreateUnknown(SqlObjectBuilder builder)

Parameters

builder SqlObjectBuilder

Source builder.

Returns

SqlObject

New SqlObject instance.

Exceptions

NotSupportedException

This method is not supported by default.

CreateView(SqlViewBuilder)

Creates a new SqlView instance.

[Pure]
protected abstract SqlView CreateView(SqlViewBuilder builder)

Parameters

builder SqlViewBuilder

Source view builder.

Returns

SqlView

New SqlView instance.

DeferCreation(SqlObjectBuilder)

Specifies whether or not an Unknown object's creation should be deferred until all tables and views are created.

[Pure]
protected virtual bool DeferCreation(SqlObjectBuilder builder)

Parameters

builder SqlObjectBuilder

SQL object builder.

Returns

bool

true when the builder is an instance of SqlConstraintBuilder type, otherwise false.

Get(string)

Returns an object with the provided name.

[Pure]
public SqlObject Get(string name)

Parameters

name string

Name of the object to return.

Returns

SqlObject

Existing object.

Exceptions

KeyNotFoundException

When object does not exist.

GetCheck(string)

Returns a check with the provided name.

[Pure]
public SqlCheck GetCheck(string name)

Parameters

name string

Name of the check to return.

Returns

SqlCheck

Existing check.

Exceptions

KeyNotFoundException

When check does not exist.

SqlObjectCastException

When object exists but is not a check.

GetEnumerator()

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

[Pure]
public SqlObjectEnumerator<SqlObject> GetEnumerator()

Returns

SqlObjectEnumerator<SqlObject>

New SqlObjectEnumerator<T> instance.

GetForeignKey(string)

Returns a foreign key with the provided name.

[Pure]
public SqlForeignKey GetForeignKey(string name)

Parameters

name string

Name of the foreign key to return.

Returns

SqlForeignKey

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 SqlIndex GetIndex(string name)

Parameters

name string

Name of the index to return.

Returns

SqlIndex

Existing index.

Exceptions

KeyNotFoundException

When index does not exist.

SqlObjectCastException

When object exists but is not an index.

GetPrimaryKey(string)

Returns a primary key with the provided name.

[Pure]
public SqlPrimaryKey GetPrimaryKey(string name)

Parameters

name string

Name of the primary key to return.

Returns

SqlPrimaryKey

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 SqlTable GetTable(string name)

Parameters

name string

Name of the table to return.

Returns

SqlTable

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 SqlView GetView(string name)

Parameters

name string

Name of the view to return.

Returns

SqlView

Existing view.

Exceptions

KeyNotFoundException

When view does not exist.

SqlObjectCastException

When object exists but is not a view.

TryGet(string)

Attempts to return an object with the provided name.

[Pure]
public SqlObject? TryGet(string name)

Parameters

name string

Name of the object to return.

Returns

SqlObject

Existing object or null when object does not exist.

TryGetCheck(string)

Attempts to return a check with the provided name.

[Pure]
public SqlCheck? TryGetCheck(string name)

Parameters

name string

Name of the check to return.

Returns

SqlCheck

Existing check or null when check does not exist.

TryGetForeignKey(string)

Attempts to return a foreign key with the provided name.

[Pure]
public SqlForeignKey? TryGetForeignKey(string name)

Parameters

name string

Name of the foreign key to return.

Returns

SqlForeignKey

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

TryGetIndex(string)

Attempts to return an index with the provided name.

[Pure]
public SqlIndex? TryGetIndex(string name)

Parameters

name string

Name of the index to return.

Returns

SqlIndex

Existing index or null when index does not exist.

TryGetPrimaryKey(string)

Attempts to return a primary key with the provided name.

[Pure]
public SqlPrimaryKey? TryGetPrimaryKey(string name)

Parameters

name string

Name of the primary key to return.

Returns

SqlPrimaryKey

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

TryGetTable(string)

Attempts to return a table with the provided name.

[Pure]
public SqlTable? TryGetTable(string name)

Parameters

name string

Name of the table to return.

Returns

SqlTable

Existing table or null when table does not exist.

TryGetView(string)

Attempts to return a view with the provided name.

[Pure]
public SqlView? TryGetView(string name)

Parameters

name string

Name of the view to return.

Returns

SqlView

Existing view or null when view does not exist.