TableBuilder<TColumns>.ForeignKey Method (String, Expression<Func<TColumns, Object>>, Boolean, String, Object)

 

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.

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

[SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public TableBuilder<TColumns> ForeignKey(
	string principalTable,
	Expression<Func<TColumns, object>> dependentKeyExpression,
	bool cascadeDelete = false,
	string name = null,
	object anonymousArguments = null
)

Parameters

principalTable
Type: System.String

Name of the table that the foreign key constraint targets.

dependentKeyExpression
Type: System.Linq.Expressions.Expression<Func<TColumns, Object>>

A lambda expression representing the properties of the foreign key. C#: t =&gt; 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 =&gt; new { t.PropertyOne, t.PropertyTwo } VB.Net: Function(t) New With { t.PropertyOne, t.PropertyTwo }

cascadeDelete
Type: System.Boolean

A value indicating whether or not cascade delete should be configured on the foreign key constraint.

name
Type: System.String

The name of this foreign key constraint. If no name is supplied, a default name will be calculated.

anonymousArguments
Type: System.Object

Additional arguments that may be processed by providers. Use anonymous type syntax to specify arguments e.g. 'new { SampleArgument = "MyValue" }'.

Return Value

Type: System.Data.Entity.Migrations.Builders.TableBuilder<TColumns>

Itself, so that multiple calls can be chained.