Share via


MigrationBuilder.AddForeignKey Method

Definition

Overloads

AddForeignKey(String, String, String, String, String, String, String, ReferentialAction, ReferentialAction)

Builds an AddForeignKeyOperation to add a new foreign key to a table.

AddForeignKey(String, String, String[], String, String, String, String[], ReferentialAction, ReferentialAction)

Builds an AddForeignKeyOperation to add a new composite (multi-column) foreign key to a table.

AddForeignKey(String, String, String, String, String, String, String, ReferentialAction, ReferentialAction)

Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs

Builds an AddForeignKeyOperation to add a new foreign key to a table.

public virtual Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation> AddForeignKey (string name, string table, string column, string principalTable, string schema = default, string principalSchema = default, string principalColumn = default, Microsoft.EntityFrameworkCore.Migrations.ReferentialAction onUpdate = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction, Microsoft.EntityFrameworkCore.Migrations.ReferentialAction onDelete = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction);
public virtual Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation> AddForeignKey (string name, string table, string column, string principalTable, string? schema = default, string? principalSchema = default, string? principalColumn = default, Microsoft.EntityFrameworkCore.Migrations.ReferentialAction onUpdate = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction, Microsoft.EntityFrameworkCore.Migrations.ReferentialAction onDelete = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction);
abstract member AddForeignKey : string * string * string * string * string * string * string * Microsoft.EntityFrameworkCore.Migrations.ReferentialAction * Microsoft.EntityFrameworkCore.Migrations.ReferentialAction -> Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation>
override this.AddForeignKey : string * string * string * string * string * string * string * Microsoft.EntityFrameworkCore.Migrations.ReferentialAction * Microsoft.EntityFrameworkCore.Migrations.ReferentialAction -> Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation>
Public Overridable Function AddForeignKey (name As String, table As String, column As String, principalTable As String, Optional schema As String = Nothing, Optional principalSchema As String = Nothing, Optional principalColumn As String = Nothing, Optional onUpdate As ReferentialAction = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction, Optional onDelete As ReferentialAction = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction) As OperationBuilder(Of AddForeignKeyOperation)

Parameters

name
String

The foreign key constraint name.

table
String

The table that contains the foreign key.

column
String

The column that is constrained.

principalTable
String

The table to which the foreign key is constrained.

schema
String

The schema that contains the table, or null if the default schema should be used.

principalSchema
String

The schema that contains principal table, or null if the default schema should be used.

principalColumn
String

The column to which the foreign key column is constrained, or null to constrain to the primary key column.

onUpdate
ReferentialAction

The action to take on updates.

onDelete
ReferentialAction

The action to take on deletes.

Returns

A builder to allow annotations to be added to the operation.

Remarks

See Database migrations for more information and examples.

Applies to

AddForeignKey(String, String, String[], String, String, String, String[], ReferentialAction, ReferentialAction)

Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs
Source:
MigrationBuilder.cs

Builds an AddForeignKeyOperation to add a new composite (multi-column) foreign key to a table.

public virtual Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation> AddForeignKey (string name, string table, string[] columns, string principalTable, string schema = default, string principalSchema = default, string[] principalColumns = default, Microsoft.EntityFrameworkCore.Migrations.ReferentialAction onUpdate = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction, Microsoft.EntityFrameworkCore.Migrations.ReferentialAction onDelete = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction);
public virtual Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation> AddForeignKey (string name, string table, string[] columns, string principalTable, string? schema = default, string? principalSchema = default, string[]? principalColumns = default, Microsoft.EntityFrameworkCore.Migrations.ReferentialAction onUpdate = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction, Microsoft.EntityFrameworkCore.Migrations.ReferentialAction onDelete = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction);
abstract member AddForeignKey : string * string * string[] * string * string * string * string[] * Microsoft.EntityFrameworkCore.Migrations.ReferentialAction * Microsoft.EntityFrameworkCore.Migrations.ReferentialAction -> Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation>
override this.AddForeignKey : string * string * string[] * string * string * string * string[] * Microsoft.EntityFrameworkCore.Migrations.ReferentialAction * Microsoft.EntityFrameworkCore.Migrations.ReferentialAction -> Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation>
Public Overridable Function AddForeignKey (name As String, table As String, columns As String(), principalTable As String, Optional schema As String = Nothing, Optional principalSchema As String = Nothing, Optional principalColumns As String() = Nothing, Optional onUpdate As ReferentialAction = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction, Optional onDelete As ReferentialAction = Microsoft.EntityFrameworkCore.Migrations.ReferentialAction.NoAction) As OperationBuilder(Of AddForeignKeyOperation)

Parameters

name
String

The foreign key constraint name.

table
String

The table that contains the foreign key.

columns
String[]

The ordered list of columns that are constrained.

principalTable
String

The table to which the foreign key is constrained.

schema
String

The schema that contains the table, or null if the default schema should be used.

principalSchema
String

The schema that contains principal table, or null if the default schema should be used.

principalColumns
String[]

The columns to which the foreign key columns are constrained, or null to constrain to the primary key columns.

onUpdate
ReferentialAction

The action to take on updates.

onDelete
ReferentialAction

The action to take on deletes.

Returns

A builder to allow annotations to be added to the operation.

Remarks

See Database migrations for more information and examples.

Applies to