Search Results for

    Show / Hide Table of Contents
    View Source

    Class AlterTableBuilder

    Provides a fluent builder for constructing 'ALTER TABLE' expressions used in database migration operations.

    Inheritance
    object
    ExpressionBuilderBase<AlterTableExpression>
    ExpressionBuilderBase<AlterTableExpression, IAlterTableColumnOptionBuilder>
    Namespace: Umbraco.Cms.Infrastructure.Migrations.Expressions.Alter.Table
    Assembly: Umbraco.Infrastructure.dll
    Syntax
    public class AlterTableBuilder : ExpressionBuilderBase<AlterTableExpression, IAlterTableColumnOptionBuilder>, IAlterTableColumnTypeBuilder, IColumnTypeBuilder<IAlterTableColumnOptionBuilder>, IAlterTableColumnOptionForeignKeyCascadeBuilder, IAlterTableColumnOptionBuilder, IColumnOptionBuilder<IAlterTableColumnOptionBuilder, IAlterTableColumnOptionForeignKeyCascadeBuilder>, IAlterTableBuilder, IExecutableBuilder, IForeignKeyCascadeBuilder<IAlterTableColumnOptionBuilder, IAlterTableColumnOptionForeignKeyCascadeBuilder>, IFluentBuilder

    Constructors

    View Source

    AlterTableBuilder(IMigrationContext, AlterTableExpression)

    Initializes a new instance of the AlterTableBuilder class.

    Declaration
    public AlterTableBuilder(IMigrationContext context, AlterTableExpression expression)
    Parameters
    Type Name Description
    IMigrationContext context

    The migration context used for the operation. (IMigrationContext)

    AlterTableExpression expression

    The expression representing the table alteration. (AlterTableExpression)

    Properties

    View Source

    CurrentColumn

    Gets or sets the current column definition being altered.

    Declaration
    public ColumnDefinition CurrentColumn { get; set; }
    Property Value
    Type Description
    ColumnDefinition
    View Source

    CurrentForeignKey

    Gets or sets the definition of the foreign key currently being altered in the table.

    Declaration
    public ForeignKeyDefinition CurrentForeignKey { get; set; }
    Property Value
    Type Description
    ForeignKeyDefinition

    Methods

    View Source

    AddColumn(string)

    Adds a new column to the table.

    Declaration
    public IAlterTableColumnTypeBuilder AddColumn(string name)
    Parameters
    Type Name Description
    string name

    The name of the column to add.

    Returns
    Type Description
    IAlterTableColumnTypeBuilder

    An IAlterTableColumnTypeBuilder to further define the column.

    View Source

    AlterColumn(string)

    Alters the column with the specified name.

    Declaration
    public IAlterTableColumnTypeBuilder AlterColumn(string name)
    Parameters
    Type Name Description
    string name

    The name of the column to alter.

    Returns
    Type Description
    IAlterTableColumnTypeBuilder

    An IAlterTableColumnTypeBuilder to continue building the alter column expression.

    View Source

    Do()

    Executes the alter table operation for the current migration expression.

    Throws a System.NotSupportedException if the underlying database is SQLite, as direct ALTER TABLE operations are not supported on that platform.

    Declaration
    public void Do()
    View Source

    ForeignKey()

    Creates a foreign key constraint from the current table to the specified primary table and column.

    Declaration
    public IAlterTableColumnOptionForeignKeyCascadeBuilder ForeignKey()
    Returns
    Type Description
    IAlterTableColumnOptionForeignKeyCascadeBuilder

    An object to configure cascade options for the foreign key constraint.

    View Source

    ForeignKey(string, string)

    Defines a foreign key constraint referencing the specified primary table and column.

    Declaration
    public IAlterTableColumnOptionForeignKeyCascadeBuilder ForeignKey(string primaryTableName, string primaryColumnName)
    Parameters
    Type Name Description
    string primaryTableName

    The name of the primary table that the foreign key references.

    string primaryColumnName

    The name of the primary column in the primary table that the foreign key references.

    Returns
    Type Description
    IAlterTableColumnOptionForeignKeyCascadeBuilder

    An object to configure foreign key cascade options.

    View Source

    ForeignKey(string, string, string)

    Defines a foreign key constraint on the table being altered.

    Declaration
    public IAlterTableColumnOptionForeignKeyCascadeBuilder ForeignKey(string foreignKeyName, string primaryTableName, string primaryColumnName)
    Parameters
    Type Name Description
    string foreignKeyName

    The name of the foreign key constraint.

    string primaryTableName

    The name of the primary table that the foreign key references.

    string primaryColumnName

    The name of the primary column in the primary table that the foreign key references.

    Returns
    Type Description
    IAlterTableColumnOptionForeignKeyCascadeBuilder

    An object to specify additional foreign key options such as cascade behavior.

    View Source

    ForeignKey(string?, string?, string, string)

    Adds a foreign key constraint to the altered table.

    Declaration
    public IAlterTableColumnOptionForeignKeyCascadeBuilder ForeignKey(string? foreignKeyName, string? primaryTableSchema, string primaryTableName, string primaryColumnName)
    Parameters
    Type Name Description
    string foreignKeyName

    The name of the foreign key constraint, or null to use a default name.

    string primaryTableSchema

    The schema of the referenced (primary) table, or null to use the default schema.

    string primaryTableName

    The name of the referenced (primary) table.

    string primaryColumnName

    The name of the referenced column in the primary table.

    Returns
    Type Description
    IAlterTableColumnOptionForeignKeyCascadeBuilder

    An object for configuring cascade options for the foreign key constraint.

    View Source

    GetColumnForType()

    Gets the definition of the current column being altered.

    Declaration
    public override ColumnDefinition GetColumnForType()
    Returns
    Type Description
    ColumnDefinition

    The ColumnDefinition for the current column.

    View Source

    Identity()

    Marks the current column as an identity column.

    Declaration
    public IAlterTableColumnOptionBuilder Identity()
    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder to continue building the column options.

    View Source

    Indexed()

    Specifies that the column should be indexed.

    Declaration
    public IAlterTableColumnOptionBuilder Indexed()
    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder that can be used to continue configuring the column alteration.

    View Source

    Indexed(string?)

    Specifies that the column should be indexed with an optional index name.

    Declaration
    public IAlterTableColumnOptionBuilder Indexed(string? indexName)
    Parameters
    Type Name Description
    string indexName

    The optional name of the index.

    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder to continue building the column options.

    View Source

    NotNullable()

    Specifies that the current column cannot contain null values.

    Declaration
    public IAlterTableColumnOptionBuilder NotNullable()
    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder for further column alteration options.

    View Source

    Nullable()

    Sets the current column to allow null values.

    Declaration
    public IAlterTableColumnOptionBuilder Nullable()
    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder for further column alteration options.

    View Source

    OnDelete(Rule)

    Specifies the action to take when a referenced row is deleted (the ON DELETE rule) for the current foreign key constraint.

    Declaration
    public IAlterTableColumnOptionForeignKeyCascadeBuilder OnDelete(Rule rule)
    Parameters
    Type Name Description
    Rule rule

    The System.Data.Rule that determines the ON DELETE behavior (e.g., CASCADE, SET NULL, etc.).

    Returns
    Type Description
    IAlterTableColumnOptionForeignKeyCascadeBuilder

    An IAlterTableColumnOptionForeignKeyCascadeBuilder to continue configuring the foreign key.

    View Source

    OnDeleteOrUpdate(Rule)

    Sets the specified rule to be applied on both delete and update actions for the table.

    Declaration
    public IAlterTableColumnOptionBuilder OnDeleteOrUpdate(Rule rule)
    Parameters
    Type Name Description
    Rule rule

    The rule to apply on delete and update.

    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder to continue building the table alteration.

    View Source

    OnUpdate(Rule)

    Sets the ON UPDATE rule for the foreign key.

    Declaration
    public IAlterTableColumnOptionForeignKeyCascadeBuilder OnUpdate(Rule rule)
    Parameters
    Type Name Description
    Rule rule

    The rule to apply on update.

    Returns
    Type Description
    IAlterTableColumnOptionForeignKeyCascadeBuilder

    An object to continue building the foreign key cascade options.

    View Source

    PrimaryKey()

    Sets the current column as the primary key for the table in the alter table expression.

    Declaration
    public IAlterTableColumnOptionBuilder PrimaryKey()
    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder that can be used to further configure the column.

    View Source

    PrimaryKey(string)

    Sets the primary key constraint on the current column of the table being altered.

    Declaration
    public IAlterTableColumnOptionBuilder PrimaryKey(string primaryKeyName)
    Parameters
    Type Name Description
    string primaryKeyName
    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder to continue building column options.

    View Source

    ReferencedBy(string, string)

    Defines a foreign key relationship where this table is referenced by the specified foreign table and column.

    Declaration
    public IAlterTableColumnOptionForeignKeyCascadeBuilder ReferencedBy(string foreignTableName, string foreignColumnName)
    Parameters
    Type Name Description
    string foreignTableName

    The name of the foreign table that references this table.

    string foreignColumnName

    The name of the foreign column in the foreign table that references this table.

    Returns
    Type Description
    IAlterTableColumnOptionForeignKeyCascadeBuilder

    An object to specify foreign key cascade options.

    View Source

    ReferencedBy(string, string, string)

    Specifies that this column is referenced by a foreign key constraint from another table.

    Declaration
    public IAlterTableColumnOptionForeignKeyCascadeBuilder ReferencedBy(string foreignKeyName, string foreignTableName, string foreignColumnName)
    Parameters
    Type Name Description
    string foreignKeyName

    The name of the foreign key constraint that references this column.

    string foreignTableName

    The name of the table containing the foreign key.

    string foreignColumnName

    The name of the column in the foreign table that references this column.

    Returns
    Type Description
    IAlterTableColumnOptionForeignKeyCascadeBuilder

    The builder for configuring the foreign key relationship.

    View Source

    ReferencedBy(string?, string?, string, string)

    Defines a foreign key relationship where this table is referenced by the specified foreign table and column.

    Declaration
    public IAlterTableColumnOptionForeignKeyCascadeBuilder ReferencedBy(string? foreignKeyName, string? foreignTableSchema, string foreignTableName, string foreignColumnName)
    Parameters
    Type Name Description
    string foreignKeyName

    The name of the foreign key constraint. Can be null.

    string foreignTableSchema

    The schema of the foreign table. Can be null.

    string foreignTableName

    The name of the foreign table.

    string foreignColumnName

    The name of the foreign column in the foreign table.

    Returns
    Type Description
    IAlterTableColumnOptionForeignKeyCascadeBuilder

    An object to specify foreign key cascade options.

    View Source

    Unique()

    Specifies that the column should have a unique constraint applied.

    Declaration
    public IAlterTableColumnOptionBuilder Unique()
    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder for further column option configuration.

    View Source

    Unique(string?)

    Marks the column as unique by adding a unique index.

    Declaration
    public IAlterTableColumnOptionBuilder Unique(string? indexName)
    Parameters
    Type Name Description
    string indexName

    The name of the unique index. If null, a default name will be used.

    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder to continue building the column options.

    View Source

    WithDefault(SystemMethods)

    Sets the default value of the current column to the specified SystemMethods value.

    Declaration
    public IAlterTableColumnOptionBuilder WithDefault(SystemMethods method)
    Parameters
    Type Name Description
    SystemMethods method

    The SystemMethods value to use as the default for the column.

    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder that can be used to further configure the column options.

    View Source

    WithDefaultValue(object)

    Sets the default value for the column being altered.

    Declaration
    public IAlterTableColumnOptionBuilder WithDefaultValue(object value)
    Parameters
    Type Name Description
    object value

    The default value to set for the column.

    Returns
    Type Description
    IAlterTableColumnOptionBuilder

    An IAlterTableColumnOptionBuilder to allow further configuration.

    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX