OwnershipBuilder.HasForeignKey(String[]) Method

Definition

Configures the property(s) to use as the foreign key for this relationship.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.OwnershipBuilder HasForeignKey (params string[] foreignKeyPropertyNames);
abstract member HasForeignKey : string[] -> Microsoft.EntityFrameworkCore.Metadata.Builders.OwnershipBuilder
override this.HasForeignKey : string[] -> Microsoft.EntityFrameworkCore.Metadata.Builders.OwnershipBuilder
Public Overridable Function HasForeignKey (ParamArray foreignKeyPropertyNames As String()) As OwnershipBuilder

Parameters

foreignKeyPropertyNames
String[]

The name(s) of the foreign key property(s).

Returns

The same builder instance so that multiple configuration calls can be chained.

Remarks

If the specified property name(s) do not exist on the entity type then a new shadow state property(s) will be added to serve as the foreign key. A shadow state property is one that does not have a corresponding property in the entity class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the entity class.

If HasPrincipalKey(String[]) is not specified, then an attempt will be made to match the data type and order of foreign key properties against the primary key of the principal entity type. If they do not match, new shadow state properties that form a unique index will be added to the principal entity type to serve as the reference key.

Applies to