Class SqlObjectExtensions
- Namespace
- LfrlAnvil.Sql.Extensions
- Assembly
- LfrlAnvil.Sql.Core.dll
Contains various ISqlObjectBuilder and ISqlObject extension methods.
public static class SqlObjectExtensions
- Inheritance
-
SqlObjectExtensions
- Inherited Members
Methods
AddStatement<T>(T, string)
Adds a custom SQL statement
to the provided changeTracker
.
public static T AddStatement<T>(this T changeTracker, string statement) where T : ISqlDatabaseChangeTracker
Parameters
changeTracker
TSource change tracker.
statement
stringSQL statement to add.
Returns
- T
changeTracker
.
Type Parameters
T
CreateIndex(ISqlConstraintBuilderCollection, params SqlOrderByNode[])
Creates a new index builder with a default name.
public static ISqlIndexBuilder CreateIndex(this ISqlConstraintBuilderCollection constraints, params SqlOrderByNode[] columns)
Parameters
constraints
ISqlConstraintBuilderCollectionSource collection.
columns
SqlOrderByNode[]Collection of columns that define the index.
Returns
- ISqlIndexBuilder
New ISqlIndexBuilder instance.
Exceptions
- SqlObjectBuilderException
When index constraint could not be created.
CreateIndex(ISqlConstraintBuilderCollection, string, params SqlOrderByNode[])
Creates a new index builder.
public static ISqlIndexBuilder CreateIndex(this ISqlConstraintBuilderCollection constraints, string name, params SqlOrderByNode[] columns)
Parameters
constraints
ISqlConstraintBuilderCollectionSource collection.
name
stringName of the index constraint.
columns
SqlOrderByNode[]Collection of columns that define the index.
Returns
- ISqlIndexBuilder
New ISqlIndexBuilder instance.
Exceptions
- SqlObjectBuilderException
When index constraint could not be created.
CreateIndex(SqlConstraintBuilderCollection, params SqlOrderByNode[])
Creates a new index builder with a default name.
public static SqlIndexBuilder CreateIndex(this SqlConstraintBuilderCollection constraints, params SqlOrderByNode[] columns)
Parameters
constraints
SqlConstraintBuilderCollectionSource collection.
columns
SqlOrderByNode[]Collection of columns that define the index.
Returns
- SqlIndexBuilder
New SqlIndexBuilder instance.
Exceptions
- SqlObjectBuilderException
When index constraint could not be created.
CreateIndex(SqlConstraintBuilderCollection, string, params SqlOrderByNode[])
Creates a new index builder.
public static SqlIndexBuilder CreateIndex(this SqlConstraintBuilderCollection constraints, string name, params SqlOrderByNode[] columns)
Parameters
constraints
SqlConstraintBuilderCollectionSource collection.
name
stringName of the index constraint.
columns
SqlOrderByNode[]Collection of columns that define the index.
Returns
- SqlIndexBuilder
New SqlIndexBuilder instance.
Exceptions
- SqlObjectBuilderException
When index constraint could not be created.
CreateUniqueIndex(ISqlConstraintBuilderCollection, params SqlOrderByNode[])
Creates a new unique index builder with a default name.
public static ISqlIndexBuilder CreateUniqueIndex(this ISqlConstraintBuilderCollection constraints, params SqlOrderByNode[] columns)
Parameters
constraints
ISqlConstraintBuilderCollectionSource collection.
columns
SqlOrderByNode[]Collection of columns that define the index.
Returns
- ISqlIndexBuilder
New ISqlIndexBuilder instance.
Exceptions
- SqlObjectBuilderException
When index constraint could not be created.
CreateUniqueIndex(ISqlConstraintBuilderCollection, string, params SqlOrderByNode[])
Creates a new unique index builder.
public static ISqlIndexBuilder CreateUniqueIndex(this ISqlConstraintBuilderCollection constraints, string name, params SqlOrderByNode[] columns)
Parameters
constraints
ISqlConstraintBuilderCollectionSource collection.
name
stringName of the index constraint.
columns
SqlOrderByNode[]Collection of columns that define the index.
Returns
- ISqlIndexBuilder
New ISqlIndexBuilder instance.
Exceptions
- SqlObjectBuilderException
When index constraint could not be created.
CreateUniqueIndex(SqlConstraintBuilderCollection, params SqlOrderByNode[])
Creates a new unique index builder with a default name.
public static SqlIndexBuilder CreateUniqueIndex(this SqlConstraintBuilderCollection constraints, params SqlOrderByNode[] columns)
Parameters
constraints
SqlConstraintBuilderCollectionSource collection.
columns
SqlOrderByNode[]Collection of columns that define the index.
Returns
- SqlIndexBuilder
New SqlIndexBuilder instance.
Exceptions
- SqlObjectBuilderException
When index constraint could not be created.
CreateUniqueIndex(SqlConstraintBuilderCollection, string, params SqlOrderByNode[])
Creates a new unique index builder.
public static SqlIndexBuilder CreateUniqueIndex(this SqlConstraintBuilderCollection constraints, string name, params SqlOrderByNode[] columns)
Parameters
constraints
SqlConstraintBuilderCollectionSource collection.
name
stringName of the index constraint.
columns
SqlOrderByNode[]Collection of columns that define the index.
Returns
- SqlIndexBuilder
New SqlIndexBuilder instance.
Exceptions
- SqlObjectBuilderException
When index constraint could not be created.
Detach<T>(T, bool)
Changes IsAttached value for the provided changeTracker
.
public static T Detach<T>(this T changeTracker, bool enabled = true) where T : ISqlDatabaseChangeTracker
Parameters
changeTracker
TSource change tracker.
enabled
boolValue to unset. true means that the change tracker will be detached. Equal to true by default.
Returns
- T
changeTracker
.
Type Parameters
T
GetOriginalValue<T>(ISqlDatabaseChangeTracker, SqlObjectBuilder, SqlObjectChangeDescriptor<T>)
Creates a new SqlObjectOriginalValue<T> instance associated with the given target
and its property's descriptor
.
[Pure]
public static SqlObjectOriginalValue<T> GetOriginalValue<T>(this ISqlDatabaseChangeTracker changeTracker, SqlObjectBuilder target, SqlObjectChangeDescriptor<T> descriptor)
Parameters
changeTracker
ISqlDatabaseChangeTrackerSource change tracker.
target
SqlObjectBuilderObject to check.
descriptor
SqlObjectChangeDescriptor<T>Property change descriptor.
Returns
- SqlObjectOriginalValue<T>
New SqlObjectOriginalValue<T> instance.
Type Parameters
T
Value type.
IsSelfReference(ISqlForeignKeyBuilder)
Checks whether or not OriginIndex and ReferencedIndex
of the provided foreignKey
belong to the same table.
[Pure]
public static bool IsSelfReference(this ISqlForeignKeyBuilder foreignKey)
Parameters
foreignKey
ISqlForeignKeyBuilderForeign key to check.
Returns
- bool
true when foreign key is a self-reference, otherwise false.
IsSelfReference(ISqlForeignKey)
Checks whether or not OriginIndex and ReferencedIndex
of the provided foreignKey
belong to the same table.
[Pure]
public static bool IsSelfReference(this ISqlForeignKey foreignKey)
Parameters
foreignKey
ISqlForeignKeyForeign key to check.
Returns
- bool
true when foreign key is a self-reference, otherwise false.
SetDefaultValue<T>(ISqlColumnBuilder, T?)
Changes DefaultValue value of the provided column
.
public static ISqlColumnBuilder SetDefaultValue<T>(this ISqlColumnBuilder column, T? value) where T : struct
Parameters
column
ISqlColumnBuilderSource column.
value
T?Value to set.
Returns
- ISqlColumnBuilder
column
.
Type Parameters
T
Value type.
Exceptions
- SqlObjectBuilderException
When default value cannot be changed.
SetDefaultValue<T>(ISqlColumnBuilder, T?)
Changes DefaultValue value of the provided column
.
public static ISqlColumnBuilder SetDefaultValue<T>(this ISqlColumnBuilder column, T? value) where T : notnull
Parameters
column
ISqlColumnBuilderSource column.
value
TValue to set.
Returns
- ISqlColumnBuilder
column
.
Type Parameters
T
Value type.
Exceptions
- SqlObjectBuilderException
When default value cannot be changed.
SetDefaultValue<T>(SqlColumnBuilder, T?)
Changes DefaultValue value of the provided column
.
public static SqlColumnBuilder SetDefaultValue<T>(this SqlColumnBuilder column, T? value) where T : struct
Parameters
column
SqlColumnBuilderSource column.
value
T?Value to set.
Returns
- SqlColumnBuilder
column
.
Type Parameters
T
Exceptions
- SqlObjectBuilderException
When default value cannot be changed.
SetDefaultValue<T>(SqlColumnBuilder, T?)
Changes DefaultValue value of the provided column
.
public static SqlColumnBuilder SetDefaultValue<T>(this SqlColumnBuilder column, T? value) where T : notnull
Parameters
column
SqlColumnBuilderSource column.
value
TValue to set.
Returns
- SqlColumnBuilder
column
.
Type Parameters
T
Exceptions
- SqlObjectBuilderException
When default value cannot be changed.
SetFilter<T>(T, Func<SqlTableBuilderNode, SqlConditionNode?>)
Changes Filter value of the provided index
.
public static T SetFilter<T>(this T index, Func<SqlTableBuilderNode, SqlConditionNode?> filter) where T : ISqlIndexBuilder
Parameters
index
TSource index.
filter
Func<SqlTableBuilderNode, SqlConditionNode>Value to set.
Returns
- T
index
.
Type Parameters
T
SQL index builder type.
Exceptions
- SqlObjectBuilderException
When filter cannot be changed.
SetPrimaryKey(ISqlConstraintBuilderCollection, params SqlOrderByNode[])
Creates a new unique index builder with a default name and sets a new primary key builder with a default name based on that index.
public static ISqlPrimaryKeyBuilder SetPrimaryKey(this ISqlConstraintBuilderCollection constraints, params SqlOrderByNode[] columns)
Parameters
constraints
ISqlConstraintBuilderCollectionSource collection.
columns
SqlOrderByNode[]Collection of columns that define the underlying index.
Returns
- ISqlPrimaryKeyBuilder
New ISqlPrimaryKeyBuilder instance.
Exceptions
- SqlObjectBuilderException
When unique index constraint or primary key constraint could not be created.
SetPrimaryKey(ISqlConstraintBuilderCollection, string, params SqlOrderByNode[])
Creates a new unique index builder with a default name and sets a new primary key builder based on that index.
public static ISqlPrimaryKeyBuilder SetPrimaryKey(this ISqlConstraintBuilderCollection constraints, string name, params SqlOrderByNode[] columns)
Parameters
constraints
ISqlConstraintBuilderCollectionSource collection.
name
stringName of the primary key constraint.
columns
SqlOrderByNode[]Collection of columns that define the underlying index.
Returns
- ISqlPrimaryKeyBuilder
New ISqlPrimaryKeyBuilder instance.
Exceptions
- SqlObjectBuilderException
When unique index constraint or primary key constraint could not be created.
SetPrimaryKey(SqlConstraintBuilderCollection, params SqlOrderByNode[])
Creates a new unique index builder with a default name and sets a new primary key builder with a default name based on that index.
public static SqlPrimaryKeyBuilder SetPrimaryKey(this SqlConstraintBuilderCollection constraints, params SqlOrderByNode[] columns)
Parameters
constraints
SqlConstraintBuilderCollectionSource collection.
columns
SqlOrderByNode[]Collection of columns that define the underlying index.
Returns
- SqlPrimaryKeyBuilder
New SqlPrimaryKeyBuilder instance.
Exceptions
- SqlObjectBuilderException
When unique index constraint or primary key constraint could not be created.
SetPrimaryKey(SqlConstraintBuilderCollection, string, params SqlOrderByNode[])
Creates a new unique index builder with a default name and sets a new primary key builder based on that index.
public static SqlPrimaryKeyBuilder SetPrimaryKey(this SqlConstraintBuilderCollection constraints, string name, params SqlOrderByNode[] columns)
Parameters
constraints
SqlConstraintBuilderCollectionSource collection.
name
stringName of the primary key constraint.
columns
SqlOrderByNode[]Collection of columns that define the underlying index.
Returns
- SqlPrimaryKeyBuilder
New SqlPrimaryKeyBuilder instance.
Exceptions
- SqlObjectBuilderException
When unique index constraint or primary key constraint could not be created.
SetType(ISqlColumnBuilder, ISqlDataType)
Changes TypeDefinition value of the provided column
.
public static ISqlColumnBuilder SetType(this ISqlColumnBuilder column, ISqlDataType dataType)
Parameters
column
ISqlColumnBuilderSource column.
dataType
ISqlDataTypeISqlDataType to use for retrieving a default type definition associated with it.
Returns
- ISqlColumnBuilder
column
.
Remarks
Changing the type will reset the DefaultValue to null.
Exceptions
- SqlObjectBuilderException
When type definition cannot be changed.
SetType(ISqlColumnBuilder, Type)
Changes TypeDefinition value of the provided column
.
public static ISqlColumnBuilder SetType(this ISqlColumnBuilder column, Type type)
Parameters
column
ISqlColumnBuilderSource column.
type
TypeRuntime type to use for retrieving a type definition associated with it.
Returns
- ISqlColumnBuilder
column
.
Remarks
Changing the type will reset the DefaultValue to null.
Exceptions
- SqlObjectBuilderException
When type definition cannot be changed.
SetType(SqlColumnBuilder, ISqlDataType)
Changes TypeDefinition value of the provided column
.
public static SqlColumnBuilder SetType(this SqlColumnBuilder column, ISqlDataType dataType)
Parameters
column
SqlColumnBuilderSource column.
dataType
ISqlDataTypeISqlDataType to use for retrieving a default type definition associated with it.
Returns
- SqlColumnBuilder
column
.
Remarks
Changing the type will reset the DefaultValue to null.
Exceptions
- SqlObjectBuilderException
When type definition cannot be changed.
SetType(SqlColumnBuilder, Type)
Changes TypeDefinition value of the provided column
.
public static SqlColumnBuilder SetType(this SqlColumnBuilder column, Type type)
Parameters
column
SqlColumnBuilderSource column.
type
TypeRuntime type to use for retrieving a type definition associated with it.
Returns
- SqlColumnBuilder
column
.
Remarks
Changing the type will reset the DefaultValue to null.
Exceptions
- SqlObjectBuilderException
When type definition cannot be changed.
SetType<T>(ISqlColumnBuilder)
Changes TypeDefinition value of the provided column
.
public static ISqlColumnBuilder SetType<T>(this ISqlColumnBuilder column)
Parameters
column
ISqlColumnBuilderSource column.
Returns
- ISqlColumnBuilder
column
.
Type Parameters
T
Runtime type to use for retrieving a type definition associated with it.
Remarks
Changing the type will reset the DefaultValue to null.
Exceptions
- SqlObjectBuilderException
When type definition cannot be changed.
SetType<T>(SqlColumnBuilder)
Changes TypeDefinition value of the provided column
.
public static SqlColumnBuilder SetType<T>(this SqlColumnBuilder column)
Parameters
column
SqlColumnBuilderSource column.
Returns
- SqlColumnBuilder
column
.
Type Parameters
T
Runtime type to use for retrieving a type definition associated with it.
Remarks
Changing the type will reset the DefaultValue to null.
Exceptions
- SqlObjectBuilderException
When type definition cannot be changed.
ToCreateNode(ISqlIndexBuilder, bool)
Creates a new SqlCreateIndexNode instance from the provided index
.
[Pure]
public static SqlCreateIndexNode ToCreateNode(this ISqlIndexBuilder index, bool replaceIfExists = false)
Parameters
index
ISqlIndexBuilderSource index.
replaceIfExists
boolSpecifies the ReplaceIfExists value. Equal to false by default.
Returns
- SqlCreateIndexNode
New SqlCreateIndexNode instance.
ToCreateNode(ISqlTableBuilder, SqlRecordSetInfo?, bool, bool, bool)
Creates a new SqlCreateTableNode instance from the provided table
.
[Pure]
public static SqlCreateTableNode ToCreateNode(this ISqlTableBuilder table, SqlRecordSetInfo? customInfo = null, bool includeForeignKeys = true, bool sortComputedColumns = false, bool ifNotExists = false)
Parameters
table
ISqlTableBuilderSource table.
customInfo
SqlRecordSetInfo?Custom SqlRecordSetInfo to use as Info of the result. Equal to null by default.
includeForeignKeys
boolSpecifies whether or not foreign key constrains should be included in the result. Equal to true by default.
sortComputedColumns
boolSpecifies whether or not columns with non-null Computation should be sorted by their computation reference depth and added to the end of the resulting collection of columns. Equal to false by default.
ifNotExists
boolSpecifies the IfNotExists value. Equal to false by default.
Returns
- SqlCreateTableNode
New SqlCreateTableNode instance.
ToCreateNode(ISqlViewBuilder, bool)
Creates a new SqlCreateViewNode instance from the provided view
.
[Pure]
public static SqlCreateViewNode ToCreateNode(this ISqlViewBuilder view, bool replaceIfExists = false)
Parameters
view
ISqlViewBuilderSource view.
replaceIfExists
boolSpecifies the ReplaceIfExists value. Equal to false by default.
Returns
- SqlCreateViewNode
New SqlCreateViewNode instance.
ToDefinitionNode(ISqlCheckBuilder)
Creates a new SqlCheckDefinitionNode instance from the provided check
.
[Pure]
public static SqlCheckDefinitionNode ToDefinitionNode(this ISqlCheckBuilder check)
Parameters
check
ISqlCheckBuilderSource check.
Returns
- SqlCheckDefinitionNode
New SqlCheckDefinitionNode instance.
ToDefinitionNode(ISqlColumnBuilder)
Creates a new SqlColumnDefinitionNode instance from the provided column
.
[Pure]
public static SqlColumnDefinitionNode ToDefinitionNode(this ISqlColumnBuilder column)
Parameters
column
ISqlColumnBuilderSource column.
Returns
- SqlColumnDefinitionNode
New SqlColumnDefinitionNode instance.
ToDefinitionNode(ISqlForeignKeyBuilder, SqlRecordSetNode)
Creates a new SqlForeignKeyDefinitionNode instance from the provided foreignKey
.
[Pure]
public static SqlForeignKeyDefinitionNode ToDefinitionNode(this ISqlForeignKeyBuilder foreignKey, SqlRecordSetNode table)
Parameters
foreignKey
ISqlForeignKeyBuilderSource foreign key.
table
SqlRecordSetNodeSQL record set node that represents the foreign key's Table.
Returns
- SqlForeignKeyDefinitionNode
New SqlForeignKeyDefinitionNode instance.
ToDefinitionNode(ISqlPrimaryKeyBuilder)
Creates a new SqlPrimaryKeyDefinitionNode instance from the provided primaryKey
.
[Pure]
public static SqlPrimaryKeyDefinitionNode ToDefinitionNode(this ISqlPrimaryKeyBuilder primaryKey)
Parameters
primaryKey
ISqlPrimaryKeyBuilderSource primary key.
Returns
- SqlPrimaryKeyDefinitionNode
New SqlPrimaryKeyDefinitionNode instance.
ToDefinitionRange(IReadOnlyCollection<ISqlColumnBuilder>, bool)
Creates a new collection of SqlColumnDefinitionNode instances from the provided columns
.
[Pure]
public static SqlColumnDefinitionNode[] ToDefinitionRange(this IReadOnlyCollection<ISqlColumnBuilder> columns, bool sortComputedColumns = false)
Parameters
columns
IReadOnlyCollection<ISqlColumnBuilder>Source collection of columns.
sortComputedColumns
boolSpecifies whether or not columns with non-null Computation should be sorted by their computation reference depth and added to the end of the resulting collection. Equal to false by default.
Returns
- SqlColumnDefinitionNode[]
New collection of SqlColumnDefinitionNode instances.