Class CreateForeignKeyBuilder
Provides a builder for creating a foreign key constraint in a database migration.
Namespace: Umbraco.Cms.Infrastructure.Migrations.Expressions.Create.ForeignKey
Assembly: Umbraco.Infrastructure.dll
Syntax
public class CreateForeignKeyBuilder : ExpressionBuilderBase<CreateForeignKeyExpression>, ICreateForeignKeyFromTableBuilder, ICreateForeignKeyForeignColumnBuilder, ICreateForeignKeyToTableBuilder, ICreateForeignKeyPrimaryColumnBuilder, ICreateForeignKeyCascadeBuilder, IFluentBuilder, IExecutableBuilder
Constructors
View SourceCreateForeignKeyBuilder(CreateForeignKeyExpression)
Initializes a new instance of the CreateForeignKeyBuilder class.
Declaration
public CreateForeignKeyBuilder(CreateForeignKeyExpression expression)
Parameters
| Type | Name | Description |
|---|---|---|
| CreateForeignKeyExpression | expression | The CreateForeignKeyExpression that defines the foreign key to be created. |
Methods
View SourceDo()
Executes.
Declaration
public void Do()
ForeignColumn(string)
Specifies the foreign column for the foreign key constraint.
Declaration
public ICreateForeignKeyToTableBuilder ForeignColumn(string column)
Parameters
| Type | Name | Description |
|---|---|---|
| string | column | The name of the foreign column. |
Returns
| Type | Description |
|---|---|
| ICreateForeignKeyToTableBuilder | The builder to specify the table the foreign key references. |
ForeignColumns(params string[])
Specifies the foreign key columns for the foreign key constraint.
Declaration
public ICreateForeignKeyToTableBuilder ForeignColumns(params string[] columns)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | columns | The names of the foreign key columns. |
Returns
| Type | Description |
|---|---|
| ICreateForeignKeyToTableBuilder | A builder to specify the referenced table for the foreign key. |
FromTable(string)
Sets the source table for the foreign key constraint.
Declaration
public ICreateForeignKeyForeignColumnBuilder FromTable(string table)
Parameters
| Type | Name | Description |
|---|---|---|
| string | table | The name of the source table. |
Returns
| Type | Description |
|---|---|
| ICreateForeignKeyForeignColumnBuilder | An ICreateForeignKeyForeignColumnBuilder for further configuration. |
OnDelete(Rule)
Sets the action to take when a referenced row is deleted by specifying the delete rule for the foreign key constraint.
Declaration
public ICreateForeignKeyCascadeBuilder OnDelete(Rule rule)
Parameters
| Type | Name | Description |
|---|---|---|
| Rule | rule | The System.Data.Rule that defines the delete behavior (e.g., Cascade, SetNull, Restrict). |
Returns
| Type | Description |
|---|---|
| ICreateForeignKeyCascadeBuilder | The current ICreateForeignKeyCascadeBuilder instance for method chaining. |
OnDeleteOrUpdate(Rule)
Configures the action to take when the referenced row is deleted or updated in the foreign key relationship.
Declaration
public IExecutableBuilder OnDeleteOrUpdate(Rule rule)
Parameters
| Type | Name | Description |
|---|---|---|
| Rule | rule | The referential action (such as Cascade, SetNull, or Restrict) to apply on delete or update. |
Returns
| Type | Description |
|---|---|
| IExecutableBuilder | An IExecutableBuilder to continue building the migration expression. |
OnUpdate(Rule)
Sets the action to take when the referenced primary key is updated for this foreign key constraint.
Declaration
public ICreateForeignKeyCascadeBuilder OnUpdate(Rule rule)
Parameters
| Type | Name | Description |
|---|---|---|
| Rule | rule | The update rule to apply (e.g., Cascade, SetNull, Restrict). |
Returns
| Type | Description |
|---|---|
| ICreateForeignKeyCascadeBuilder | The current ICreateForeignKeyCascadeBuilder instance for method chaining. |
PrimaryColumn(string)
Specifies the primary (referenced) column for the foreign key constraint.
Declaration
public ICreateForeignKeyCascadeBuilder PrimaryColumn(string column)
Parameters
| Type | Name | Description |
|---|---|---|
| string | column | The name of the primary (referenced) column. |
Returns
| Type | Description |
|---|---|
| ICreateForeignKeyCascadeBuilder | An ICreateForeignKeyCascadeBuilder to continue building the foreign key. |
PrimaryColumns(params string[])
Specifies the primary key columns for the foreign key.
Declaration
public ICreateForeignKeyCascadeBuilder PrimaryColumns(params string[] columns)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | columns | The names of the primary key columns. |
Returns
| Type | Description |
|---|---|
| ICreateForeignKeyCascadeBuilder | An ICreateForeignKeyCascadeBuilder to continue building the foreign key. |
ToTable(string)
Specifies the table to which the foreign key will reference.
Declaration
public ICreateForeignKeyPrimaryColumnBuilder ToTable(string table)
Parameters
| Type | Name | Description |
|---|---|---|
| string | table | The name of the table to reference. |
Returns
| Type | Description |
|---|---|
| ICreateForeignKeyPrimaryColumnBuilder | A builder to specify the primary column of the foreign key. |