DbMigration.AddForeignKey Method (String, String[], String, String[], Boolean, String, Object)

[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]

Adds an operation to create a new foreign key constraint. Entity Framework Migrations APIs are not designed to accept input provided by untrusted sources (such as the end user of an application). If input is accepted from such sources it should be validated before being passed to these APIs to protect against SQL injection attacks etc.

Namespace:  System.Data.Entity.Migrations
Assembly:  EntityFramework (in EntityFramework.dll)

Syntax

'Declaration
<SuppressMessageAttribute("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")> _
Protected Friend Sub AddForeignKey ( _
    dependentTable As String, _
    dependentColumns As String(), _
    principalTable As String, _
    principalColumns As String(), _
    cascadeDelete As Boolean, _
    name As String, _
    anonymousArguments As Object _
)
'Usage
Dim dependentTable As String 
Dim dependentColumns As String()
Dim principalTable As String 
Dim principalColumns As String()
Dim cascadeDelete As Boolean 
Dim name As String 
Dim anonymousArguments As Object 

Me.AddForeignKey(dependentTable, _
    dependentColumns, principalTable, _
    principalColumns, cascadeDelete, _
    name, anonymousArguments)
[SuppressMessageAttribute("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
protected internal void AddForeignKey(
    string dependentTable,
    string[] dependentColumns,
    string principalTable,
    string[] principalColumns,
    bool cascadeDelete,
    string name,
    Object anonymousArguments
)
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1026:DefaultParametersShouldNotBeUsed")]
protected public:
void AddForeignKey(
    String^ dependentTable, 
    array<String^>^ dependentColumns, 
    String^ principalTable, 
    array<String^>^ principalColumns, 
    bool cascadeDelete, 
    String^ name, 
    Object^ anonymousArguments
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")>]
member AddForeignKey : 
        dependentTable:string * 
        dependentColumns:string[] * 
        principalTable:string * 
        principalColumns:string[] * 
        cascadeDelete:bool * 
        name:string * 
        anonymousArguments:Object -> unit
function AddForeignKey(
    dependentTable : String, 
    dependentColumns : String[], 
    principalTable : String, 
    principalColumns : String[], 
    cascadeDelete : boolean, 
    name : String, 
    anonymousArguments : Object
)

Parameters

  • dependentTable
    Type: System.String
    The table that contains the foreign key columns. Schema name is optional, if no schema is specified then dbo is assumed.
  • dependentColumns
    Type: System.String[]
    The foreign key columns.
  • principalTable
    Type: System.String
    The table that contains the columns this foreign key references. Schema name is optional, if no schema is specified then dbo is assumed.
  • principalColumns
    Type: System.String[]
    The columns this foreign key references. If no value is supplied the primary key of the principal table will be referenced.
  • cascadeDelete
    Type: System.Boolean
    A value indicating if cascade delete should be configured for the foreign key relationship. If no value is supplied, cascade delete will be off.
  • name
    Type: System.String
    The name of the foreign key constraint in the database. If no value is supplied a unique name will be generated.
  • anonymousArguments
    Type: System.Object
    The additional arguments that may be processed by providers. Use anonymous type syntax to specify arguments e.g. 'new { SampleArgument = "MyValue" }'.

See Also

Reference

DbMigration Class

AddForeignKey Overload

System.Data.Entity.Migrations Namespace