Class SqlConstraintCollection
Represents a collection of SQL table constraints.
public abstract class SqlConstraintCollection : ISqlConstraintCollection, IReadOnlyCollection<ISqlConstraint>, IEnumerable<ISqlConstraint>, IEnumerable
- Inheritance
-
SqlConstraintCollection
- Implements
- Derived
- Inherited Members
Constructors
SqlConstraintCollection(SqlConstraintBuilderCollection)
Creates a new SqlConstraintCollection instance.
protected SqlConstraintCollection(SqlConstraintBuilderCollection source)
Parameters
source
SqlConstraintBuilderCollectionSource builder 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.
PrimaryKey
Table's primary key constraint.
public SqlPrimaryKey PrimaryKey { get; }
Property Value
Table
Table that this collection belongs to.
public SqlTable Table { get; }
Property Value
Methods
Contains(string)
Checks whether or not a constraint with the provided name
exists.
[Pure]
public bool Contains(string name)
Parameters
name
stringName to check.
Returns
- bool
true when constraint exists, otherwise false.
Get(string)
Returns a constraint with the provided name
.
[Pure]
public SqlConstraint Get(string name)
Parameters
name
stringName of the constraint to return.
Returns
- SqlConstraint
Existing constraint.
Exceptions
- KeyNotFoundException
When constraint does not exist.
GetCheck(string)
Returns a check with the provided name
.
[Pure]
public SqlCheck GetCheck(string name)
Parameters
name
stringName of the check to return.
Returns
- SqlCheck
Existing check.
Exceptions
- KeyNotFoundException
When check does not exist.
- SqlObjectCastException
When constraint exists but is not a check.
GetEnumerator()
Creates a new SqlObjectEnumerator<T> instance for this collection.
[Pure]
public SqlObjectEnumerator<SqlConstraint> GetEnumerator()
Returns
- SqlObjectEnumerator<SqlConstraint>
New SqlObjectEnumerator<T> instance.
GetForeignKey(string)
Returns a foreign key with the provided name
.
[Pure]
public SqlForeignKey GetForeignKey(string name)
Parameters
name
stringName of the foreign key to return.
Returns
- SqlForeignKey
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 SqlIndex GetIndex(string name)
Parameters
name
stringName of the index to return.
Returns
- SqlIndex
Existing index.
Exceptions
- KeyNotFoundException
When index does not exist.
- SqlObjectCastException
When constraint exists but is not an index.
TryGet(string)
Attempts to return a constraint with the provided name
.
[Pure]
public SqlConstraint? TryGet(string name)
Parameters
name
stringName of the constraint to return.
Returns
- SqlConstraint
Existing constraint or null when constraint does not exist.
TryGetCheck(string)
Attempts to return a check with the provided name
.
[Pure]
public SqlCheck? TryGetCheck(string name)
Parameters
name
stringName 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
stringName 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
stringName of the index to return.
Returns
- SqlIndex
Existing index or null when index does not exist.