TableBuilder<TColumns>.ForeignKey Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Specifies a foreign key constraint to be created on the table.
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.
public System.Data.Entity.Migrations.Builders.TableBuilder<TColumns> ForeignKey (string principalTable, System.Linq.Expressions.Expression<Func<TColumns,object>> dependentKeyExpression, bool cascadeDelete = false, string name = null, object anonymousArguments = null);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public System.Data.Entity.Migrations.Builders.TableBuilder<TColumns> ForeignKey (string principalTable, System.Linq.Expressions.Expression<Func<TColumns,object>> dependentKeyExpression, bool cascadeDelete = false, string name = null, object anonymousArguments = null);
member this.ForeignKey : string * System.Linq.Expressions.Expression<Func<'Columns, obj>> * bool * string * obj -> System.Data.Entity.Migrations.Builders.TableBuilder<'Columns>
Public Function ForeignKey (principalTable As String, dependentKeyExpression As Expression(Of Func(Of TColumns, Object)), Optional cascadeDelete As Boolean = false, Optional name As String = null, Optional anonymousArguments As Object = null) As TableBuilder(Of TColumns)
Parameters
- principalTable
- String
Name of the table that the foreign key constraint targets.
- dependentKeyExpression
- Expression<Func<TColumns,Object>>
A lambda expression representing the properties of the foreign key. C#: t => t.PropertyOne VB.Net: Function(t) t.PropertyOne If multiple properties make up the foreign key then specify an anonymous type including the properties. C#: t => new { t.PropertyOne, t.PropertyTwo } VB.Net: Function(t) New With { t.PropertyOne, t.PropertyTwo }
- cascadeDelete
- Boolean
A value indicating whether or not cascade delete should be configured on the foreign key constraint.
- name
- String
The name of this foreign key constraint. If no name is supplied, a default name will be calculated.
- anonymousArguments
- Object
Additional arguments that may be processed by providers. Use anonymous type syntax to specify arguments e.g. 'new { SampleArgument = "MyValue" }'.
Returns
Itself, so that multiple calls can be chained.
- Attributes
Applies to
Entity Framework