Class CreateColumnBuilder
Provides a fluent builder for defining and configuring a new column as part of a database migration.
Inheritance
Namespace: Umbraco.Cms.Infrastructure.Migrations.Expressions.Create.Column
Assembly: Umbraco.Infrastructure.dll
Syntax
public class CreateColumnBuilder : ExpressionBuilderBase<CreateColumnExpression, ICreateColumnOptionBuilder>, ICreateColumnOnTableBuilder, ICreateColumnTypeBuilder, IColumnTypeBuilder<ICreateColumnOptionBuilder>, ICreateColumnOptionForeignKeyCascadeBuilder, ICreateColumnOptionBuilder, IColumnOptionBuilder<ICreateColumnOptionBuilder, ICreateColumnOptionForeignKeyCascadeBuilder>, IExecutableBuilder, IForeignKeyCascadeBuilder<ICreateColumnOptionBuilder, ICreateColumnOptionForeignKeyCascadeBuilder>, IFluentBuilder
Constructors
View SourceCreateColumnBuilder(IMigrationContext, CreateColumnExpression)
Initializes a new instance of the CreateColumnBuilder class.
Declaration
public CreateColumnBuilder(IMigrationContext context, CreateColumnExpression expression)
Parameters
| Type | Name | Description |
|---|---|---|
| IMigrationContext | context | The migration context. |
| CreateColumnExpression | expression | The create column expression. |
Properties
View SourceCurrentForeignKey
Gets or sets the current foreign key definition associated with the column.
Declaration
public ForeignKeyDefinition? CurrentForeignKey { get; set; }
Property Value
| Type | Description |
|---|---|
| ForeignKeyDefinition |
Methods
View SourceDo()
Executes the associated create column expression for the migration.
Declaration
public void Do()
ForeignKey()
Specifies a foreign key constraint for the column referencing the given primary table and column.
Declaration
public ICreateColumnOptionForeignKeyCascadeBuilder ForeignKey()
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionForeignKeyCascadeBuilder | An object for configuring cascade options on the foreign key constraint. |
ForeignKey(string, string)
Defines a foreign key constraint on the column referencing the specified primary table and column.
Declaration
public ICreateColumnOptionForeignKeyCascadeBuilder 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 referenced table. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionForeignKeyCascadeBuilder | A builder to specify foreign key cascade options. |
ForeignKey(string, string, string)
Defines a foreign key constraint on the column, using the specified constraint name, and referencing the given primary table and column.
Declaration
public ICreateColumnOptionForeignKeyCascadeBuilder 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 referenced by the foreign key. |
| string | primaryColumnName | The name of the primary column in the referenced table. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionForeignKeyCascadeBuilder | An ICreateColumnOptionForeignKeyCascadeBuilder to specify cascade options for the foreign key. |
ForeignKey(string?, string?, string, string)
Defines a foreign key constraint for the column being created.
Declaration
public ICreateColumnOptionForeignKeyCascadeBuilder ForeignKey(string? foreignKeyName, string? primaryTableSchema, string primaryTableName, string primaryColumnName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | foreignKeyName | The name of the foreign key constraint. Can be null. |
| string | primaryTableSchema | The schema of the primary table. Can be null. |
| string | primaryTableName | The name of the primary table. |
| string | primaryColumnName | The name of the primary column in the primary table. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionForeignKeyCascadeBuilder | A builder to specify cascade options for the foreign key. |
GetColumnForType()
Returns the column definition associated with the current column expression.
Declaration
public override ColumnDefinition GetColumnForType()
Returns
| Type | Description |
|---|---|
| ColumnDefinition | The ColumnDefinition for the current column. |
Identity()
Configures the column as an identity column, meaning its value will be automatically generated and incremented by the database.
Declaration
public ICreateColumnOptionBuilder Identity()
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder that can be used to further configure the column. |
Indexed()
Marks the column as indexed.
Declaration
public ICreateColumnOptionBuilder Indexed()
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder to allow further configuration of the column. |
Indexed(string?)
Specifies that the column should be indexed with an optional index name.
Declaration
public ICreateColumnOptionBuilder Indexed(string? indexName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | indexName | The name of the index to create. If null, a default name will be used. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder to continue building the column options. |
NotNullable()
Marks the column as not nullable.
Declaration
public ICreateColumnOptionBuilder NotNullable()
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder to continue building the column. |
Nullable()
Marks the column as nullable.
Declaration
public ICreateColumnOptionBuilder Nullable()
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder to continue building the column options. |
OnDelete(Rule)
Specifies the action to take when a referenced row in the foreign key is deleted.
Declaration
public ICreateColumnOptionForeignKeyCascadeBuilder OnDelete(Rule rule)
Parameters
| Type | Name | Description |
|---|---|---|
| Rule | rule | The System.Data.Rule that determines the delete behavior for the foreign key constraint. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionForeignKeyCascadeBuilder | An ICreateColumnOptionForeignKeyCascadeBuilder to continue configuring the column options. |
OnDeleteOrUpdate(Rule)
Sets the specified referential action rule to apply to both delete and update operations for the foreign key constraint on this column.
Declaration
public ICreateColumnOptionBuilder OnDeleteOrUpdate(Rule rule)
Parameters
| Type | Name | Description |
|---|---|---|
| Rule | rule | The System.Data.Rule to apply for both delete and update actions (e.g., Cascade, SetNull). |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder that can be used to continue configuring the column options. |
OnTable(string)
Specifies the table name for the column being created.
Declaration
public ICreateColumnTypeBuilder OnTable(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the table. |
Returns
| Type | Description |
|---|---|
| ICreateColumnTypeBuilder | An ICreateColumnTypeBuilder to continue building the column. |
OnUpdate(Rule)
Sets the ON UPDATE rule for the foreign key constraint.
Declaration
public ICreateColumnOptionForeignKeyCascadeBuilder OnUpdate(Rule rule)
Parameters
| Type | Name | Description |
|---|---|---|
| Rule | rule | The rule to apply on update. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionForeignKeyCascadeBuilder | The current ICreateColumnOptionForeignKeyCascadeBuilder instance for chaining. |
PrimaryKey()
Marks the column as a primary key.
Declaration
public ICreateColumnOptionBuilder PrimaryKey()
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder to allow further configuration of the column. |
PrimaryKey(string)
Marks the column as a primary key with the specified constraint name.
Declaration
public ICreateColumnOptionBuilder PrimaryKey(string primaryKeyName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | primaryKeyName | The name of the primary key constraint. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder that can be used for further column configuration. |
ReferencedBy(string, string)
Specifies the foreign key relationship by referencing a foreign table and column.
Declaration
public ICreateColumnOptionForeignKeyCascadeBuilder ReferencedBy(string foreignTableName, string foreignColumnName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | foreignTableName | The name of the foreign table to reference. |
| string | foreignColumnName | The name of the foreign column to reference. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionForeignKeyCascadeBuilder | An ICreateColumnOptionForeignKeyCascadeBuilder to allow further configuration of the foreign key cascade options. |
ReferencedBy(string, string, string)
Specifies the foreign key relationship by referencing a foreign table and column with a specific foreign key name.
Declaration
public ICreateColumnOptionForeignKeyCascadeBuilder ReferencedBy(string foreignKeyName, string foreignTableName, string foreignColumnName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | foreignKeyName | The name of the foreign key constraint. |
| string | foreignTableName | The name of the foreign table to reference. |
| string | foreignColumnName | The name of the foreign column to reference. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionForeignKeyCascadeBuilder | An ICreateColumnOptionForeignKeyCascadeBuilder to allow further configuration of the foreign key cascade options. |
ReferencedBy(string?, string?, string, string)
Defines a foreign key constraint referencing the specified table and column.
Declaration
public ICreateColumnOptionForeignKeyCascadeBuilder 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. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionForeignKeyCascadeBuilder | An ICreateColumnOptionForeignKeyCascadeBuilder to specify cascade options. |
Unique()
Specifies that the column should have a unique constraint, ensuring all values in the column are distinct.
Declaration
public ICreateColumnOptionBuilder Unique()
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder for further column option configuration. |
Unique(string?)
Specifies that the column should have a unique index.
Declaration
public ICreateColumnOptionBuilder 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 |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder to continue building the column options. |
WithDefault(SystemMethods)
Sets the default value of the column to the specified system method.
Declaration
public ICreateColumnOptionBuilder WithDefault(SystemMethods method)
Parameters
| Type | Name | Description |
|---|---|---|
| SystemMethods | method | The system method to use as the default value. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An object to continue building column options. |
WithDefaultValue(object)
Sets the default value for the column.
Declaration
public ICreateColumnOptionBuilder WithDefaultValue(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The default value to set for the column. |
Returns
| Type | Description |
|---|---|
| ICreateColumnOptionBuilder | An ICreateColumnOptionBuilder to continue building the column options. |