RuntimeEntityType.AddForeignKey Method

Definition

Adds a new relationship to this entity type.

public virtual Microsoft.EntityFrameworkCore.Metadata.RuntimeForeignKey AddForeignKey (System.Collections.Generic.IReadOnlyList<Microsoft.EntityFrameworkCore.Metadata.RuntimeProperty> properties, Microsoft.EntityFrameworkCore.Metadata.RuntimeKey principalKey, Microsoft.EntityFrameworkCore.Metadata.RuntimeEntityType principalEntityType, Microsoft.EntityFrameworkCore.DeleteBehavior deleteBehavior = Microsoft.EntityFrameworkCore.DeleteBehavior.ClientSetNull, bool unique = false, bool required = false, bool requiredDependent = false, bool ownership = false);
abstract member AddForeignKey : System.Collections.Generic.IReadOnlyList<Microsoft.EntityFrameworkCore.Metadata.RuntimeProperty> * Microsoft.EntityFrameworkCore.Metadata.RuntimeKey * Microsoft.EntityFrameworkCore.Metadata.RuntimeEntityType * Microsoft.EntityFrameworkCore.DeleteBehavior * bool * bool * bool * bool -> Microsoft.EntityFrameworkCore.Metadata.RuntimeForeignKey
override this.AddForeignKey : System.Collections.Generic.IReadOnlyList<Microsoft.EntityFrameworkCore.Metadata.RuntimeProperty> * Microsoft.EntityFrameworkCore.Metadata.RuntimeKey * Microsoft.EntityFrameworkCore.Metadata.RuntimeEntityType * Microsoft.EntityFrameworkCore.DeleteBehavior * bool * bool * bool * bool -> Microsoft.EntityFrameworkCore.Metadata.RuntimeForeignKey
Public Overridable Function AddForeignKey (properties As IReadOnlyList(Of RuntimeProperty), principalKey As RuntimeKey, principalEntityType As RuntimeEntityType, Optional deleteBehavior As DeleteBehavior = Microsoft.EntityFrameworkCore.DeleteBehavior.ClientSetNull, Optional unique As Boolean = false, Optional required As Boolean = false, Optional requiredDependent As Boolean = false, Optional ownership As Boolean = false) As RuntimeForeignKey

Parameters

properties
IReadOnlyList<RuntimeProperty>

The properties that the foreign key is defined on.

principalKey
RuntimeKey

The primary or alternate key that is referenced.

principalEntityType
RuntimeEntityType

The entity type that the relationship targets. This may be different from the type that principalKey is defined on when the relationship targets a derived type in an inheritance hierarchy (since the key is defined on the base type of the hierarchy).

deleteBehavior
DeleteBehavior

A value indicating how a delete operation is applied to dependent entities in the relationship when the principal is deleted or the relationship is severed.

unique
Boolean

A value indicating whether the values assigned to the foreign key properties are unique.

required
Boolean

A value indicating whether the principal entity is required.

requiredDependent
Boolean

A value indicating whether the dependent entity is required.

ownership
Boolean

A value indicating whether this relationship defines an ownership.

Returns

The newly created foreign key.

Applies to