ConventionEntityTypeExtensions.AddForeignKey Method

Definition

Adds a new relationship to this entity type.

public static Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey AddForeignKey (this Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType entityType, Microsoft.EntityFrameworkCore.Metadata.IConventionProperty property, Microsoft.EntityFrameworkCore.Metadata.IConventionKey principalKey, Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType principalEntityType, bool fromDataAnnotation = false);
static member AddForeignKey : Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType * Microsoft.EntityFrameworkCore.Metadata.IConventionProperty * Microsoft.EntityFrameworkCore.Metadata.IConventionKey * Microsoft.EntityFrameworkCore.Metadata.IConventionEntityType * bool -> Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey
<Extension()>
Public Function AddForeignKey (entityType As IConventionEntityType, property As IConventionProperty, principalKey As IConventionKey, principalEntityType As IConventionEntityType, Optional fromDataAnnotation As Boolean = false) As IConventionForeignKey

Parameters

entityType
IConventionEntityType

The entity type.

property
IConventionProperty

The property that the foreign key is defined on.

principalKey
IConventionKey

The primary or alternate key that is referenced.

principalEntityType
IConventionEntityType

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).

fromDataAnnotation
Boolean

Indicates whether the configuration was specified using a data annotation.

Returns

The newly created foreign key.

Applies to