Class CreateTableBuilder
Provides a fluent builder for defining and creating database tables as part of a migration.
Inheritance
Namespace: Umbraco.Cms.Infrastructure.Migrations.Expressions.Create.Table
Assembly: Umbraco.Infrastructure.dll
Syntax
public class CreateTableBuilder : ExpressionBuilderBase<CreateTableExpression, ICreateTableColumnOptionBuilder>, ICreateTableColumnAsTypeBuilder, IColumnTypeBuilder<ICreateTableColumnOptionBuilder>, ICreateTableColumnOptionForeignKeyCascadeBuilder, ICreateTableColumnOptionBuilder, IColumnOptionBuilder<ICreateTableColumnOptionBuilder, ICreateTableColumnOptionForeignKeyCascadeBuilder>, ICreateTableWithColumnBuilder, IExecutableBuilder, IForeignKeyCascadeBuilder<ICreateTableColumnOptionBuilder, ICreateTableColumnOptionForeignKeyCascadeBuilder>, IFluentBuilder
Constructors
View SourceCreateTableBuilder(IMigrationContext, CreateTableExpression)
Initializes a new instance of the CreateTableBuilder class.
Declaration
public CreateTableBuilder(IMigrationContext context, CreateTableExpression expression)
Parameters
| Type | Name | Description |
|---|---|---|
| IMigrationContext | context | The migration context used for the table creation operation. (IMigrationContext) |
| CreateTableExpression | expression | The expression that defines the table to be created. (CreateTableExpression) |
Properties
View SourceCurrentColumn
Gets or sets the ColumnDefinition instance representing the column currently being configured in the table creation process.
Declaration
public ColumnDefinition CurrentColumn { get; set; }
Property Value
| Type | Description |
|---|---|
| ColumnDefinition |
CurrentForeignKey
Gets or sets the definition of the foreign key currently being configured during the table creation process.
Declaration
public ForeignKeyDefinition CurrentForeignKey { get; set; }
Property Value
| Type | Description |
|---|---|
| ForeignKeyDefinition |
Methods
View SourceDo()
Executes.
Declaration
public void Do()
ForeignKey()
Configures the current column as a foreign key referencing another table.
Declaration
public ICreateTableColumnOptionForeignKeyCascadeBuilder ForeignKey()
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionForeignKeyCascadeBuilder | The next step in the column option builder chain. |
ForeignKey(string, string)
Specifies a foreign key constraint for the current column, referencing a primary key in another table.
Declaration
public ICreateTableColumnOptionForeignKeyCascadeBuilder ForeignKey(string primaryTableName, string primaryColumnName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | primaryTableName | The name of the table containing the primary key to reference. |
| string | primaryColumnName | The name of the primary key column in the referenced table. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionForeignKeyCascadeBuilder | An object representing the next step in the column option builder chain, allowing further configuration. |
ForeignKey(string, string, string)
Specifies a foreign key constraint for the current column, referencing a primary key in another table.
Declaration
public ICreateTableColumnOptionForeignKeyCascadeBuilder 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 table containing the primary key to reference. |
| string | primaryColumnName | The name of the primary key column in the referenced table. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionForeignKeyCascadeBuilder | An object representing the next step in the column option builder chain, allowing further configuration. |
ForeignKey(string?, string?, string, string)
Specifies a foreign key constraint for the current column, referencing a primary key in another table.
Declaration
public ICreateTableColumnOptionForeignKeyCascadeBuilder ForeignKey(string? foreignKeyName, string? primaryTableSchema, string primaryTableName, string primaryColumnName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | foreignKeyName | The name of the foreign key constraint. |
| string | primaryTableSchema | The schema of the table containing the primary key to reference. |
| string | primaryTableName | The name of the table containing the primary key to reference. |
| string | primaryColumnName | The name of the primary key column in the referenced table. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionForeignKeyCascadeBuilder | An object representing the next step in the column option builder chain, allowing further configuration. |
GetColumnForType()
Gets the column definition for the current column type.
Declaration
public override ColumnDefinition GetColumnForType()
Returns
| Type | Description |
|---|---|
| ColumnDefinition | The Umbraco.Cms.Infrastructure.Migrations.Expressions.ColumnDefinition representing the current column. |
Identity()
Marks the column as an identity column, meaning its value will be automatically generated by the database.
Declaration
public ICreateTableColumnOptionBuilder Identity()
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next step in the column option builder chain. |
Indexed()
Marks the column as indexed by creating a non-unique index on it.
Declaration
public ICreateTableColumnOptionBuilder Indexed()
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next builder in the expression chain. |
Indexed(string?)
Marks the column as indexed and assigns the specified index name.
Declaration
public ICreateTableColumnOptionBuilder Indexed(string? indexName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | indexName | The name to assign to the created index. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next step in the column option builder chain. |
NotNullable()
Marks the column as not nullable.
Declaration
public ICreateTableColumnOptionBuilder NotNullable()
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next step in the column option builder chain. |
Nullable()
Sets the column as nullable, allowing it to store null values.
Declaration
public ICreateTableColumnOptionBuilder Nullable()
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next step in the column option builder chain. |
OnDelete(Rule)
Specifies a rule on deletes.
Declaration
public ICreateTableColumnOptionForeignKeyCascadeBuilder OnDelete(Rule rule)
Parameters
| Type | Name | Description |
|---|---|---|
| Rule | rule |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionForeignKeyCascadeBuilder |
OnDeleteOrUpdate(Rule)
Specifies a rule on deletes and updates.
Declaration
public ICreateTableColumnOptionBuilder OnDeleteOrUpdate(Rule rule)
Parameters
| Type | Name | Description |
|---|---|---|
| Rule | rule |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder |
OnUpdate(Rule)
Specifies the action to take when the referenced primary key is updated.
Declaration
public ICreateTableColumnOptionForeignKeyCascadeBuilder OnUpdate(Rule rule)
Parameters
| Type | Name | Description |
|---|---|---|
| Rule | rule | The rule to apply on update (e.g., cascade, set null, restrict). |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionForeignKeyCascadeBuilder | The next foreign key cascade builder. |
PrimaryKey()
Specifies that the column should be defined as a primary key in the database schema.
Declaration
public ICreateTableColumnOptionBuilder PrimaryKey()
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next step in the column option builder chain. |
PrimaryKey(string)
Sets a primary key constraint on the column with the specified constraint name.
Declaration
public ICreateTableColumnOptionBuilder PrimaryKey(string primaryKeyName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | primaryKeyName | The name to assign to the primary key constraint. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next step in the column option builder chain. |
ReferencedBy(string, string)
Specifies that this column is the target of a foreign key from another table.
Declaration
public ICreateTableColumnOptionForeignKeyCascadeBuilder ReferencedBy(string foreignTableName, string foreignColumnName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | foreignTableName | The name of the table containing the foreign key that references this column. |
| string | foreignColumnName | The name of the column in the foreign table that references this column. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionForeignKeyCascadeBuilder | An object representing the next step in the migration expression. |
ReferencedBy(string, string, string)
Specifies that this column is referenced by a foreign key constraint from another table.
Declaration
public ICreateTableColumnOptionForeignKeyCascadeBuilder 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 |
|---|---|
| ICreateTableColumnOptionForeignKeyCascadeBuilder | The builder for configuring the foreign key relationship. |
ReferencedBy(string?, string?, string, string)
Specifies that this column is the target of a foreign key from another table.
Declaration
public ICreateTableColumnOptionForeignKeyCascadeBuilder ReferencedBy(string? foreignKeyName, string? foreignTableSchema, string foreignTableName, string foreignColumnName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | foreignKeyName | The name of the foreign key constraint. |
| string | foreignTableSchema | The schema of the table containing the foreign key that references this column. |
| string | foreignTableName | The name of the table containing the foreign key that references this column. |
| string | foreignColumnName | The name of the column in the foreign table that references this column. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionForeignKeyCascadeBuilder | An object representing the next step in the migration expression. |
Unique()
Specifies that the column should have a unique constraint applied, ensuring all values in the column are distinct.
Declaration
public ICreateTableColumnOptionBuilder Unique()
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next step in the column option builder expression chain. |
Unique(string?)
Applies a unique constraint to the column using the specified index name, ensuring all values in the column are distinct.
Declaration
public ICreateTableColumnOptionBuilder Unique(string? indexName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | indexName | The name of the unique index to create for the column. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next step in the column option builder expression chain. |
WithColumn(string)
Adds a new column with the specified name to the table being created.
Declaration
public ICreateTableColumnAsTypeBuilder WithColumn(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the column to add. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnAsTypeBuilder | An ICreateTableColumnAsTypeBuilder to specify the column type and constraints. |
WithDefault(SystemMethods)
Sets the default value for the column using the specified SystemMethods method.
Declaration
public ICreateTableColumnOptionBuilder WithDefault(SystemMethods method)
Parameters
| Type | Name | Description |
|---|---|---|
| SystemMethods | method | The SystemMethods value representing the system method to use as the column's default value. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | The next step in the column option builder chain. |
WithDefaultValue(object)
Specifies a default value for the current column being defined.
Declaration
public ICreateTableColumnOptionBuilder WithDefaultValue(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The default value to set for the column. |
Returns
| Type | Description |
|---|---|
| ICreateTableColumnOptionBuilder | An ICreateTableColumnOptionBuilder for further column configuration. |