MutableEntityTypeExtensions.AddForeignKey Method

Definition

Adds a new relationship to this entity type.

public static Microsoft.EntityFrameworkCore.Metadata.IMutableForeignKey AddForeignKey (this Microsoft.EntityFrameworkCore.Metadata.IMutableEntityType entityType, Microsoft.EntityFrameworkCore.Metadata.IMutableProperty property, Microsoft.EntityFrameworkCore.Metadata.IMutableKey principalKey, Microsoft.EntityFrameworkCore.Metadata.IMutableEntityType principalEntityType);
static member AddForeignKey : Microsoft.EntityFrameworkCore.Metadata.IMutableEntityType * Microsoft.EntityFrameworkCore.Metadata.IMutableProperty * Microsoft.EntityFrameworkCore.Metadata.IMutableKey * Microsoft.EntityFrameworkCore.Metadata.IMutableEntityType -> Microsoft.EntityFrameworkCore.Metadata.IMutableForeignKey
<Extension()>
Public Function AddForeignKey (entityType As IMutableEntityType, property As IMutableProperty, principalKey As IMutableKey, principalEntityType As IMutableEntityType) As IMutableForeignKey

Parameters

entityType
IMutableEntityType

The entity type.

property
IMutableProperty

The property that the foreign key is defined on.

principalKey
IMutableKey

The primary or alternate key that is referenced.

principalEntityType
IMutableEntityType

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

Returns

The newly created foreign key.

Applies to