ReferenceOwnershipBuilder<TEntity,TRelatedEntity>.HasForeignKey Method

Definition

Overloads

HasForeignKey(Expression<Func<TRelatedEntity,Object>>)

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

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(Expression<Func<TEntity,Object>>) 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.

HasForeignKey(String[])

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

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.

HasForeignKey(Expression<Func<TRelatedEntity,Object>>)

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

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(Expression<Func<TEntity,Object>>) 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.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceOwnershipBuilder<TEntity,TRelatedEntity> HasForeignKey (System.Linq.Expressions.Expression<Func<TRelatedEntity,object>> foreignKeyExpression);
override this.HasForeignKey : System.Linq.Expressions.Expression<Func<'RelatedEntity, obj>> -> Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceOwnershipBuilder<'Entity, 'RelatedEntity (requires 'Entity : null and 'RelatedEntity : null)>
Public Overridable Function HasForeignKey (foreignKeyExpression As Expression(Of Func(Of TRelatedEntity, Object))) As ReferenceOwnershipBuilder(Of TEntity, TRelatedEntity)

Parameters

foreignKeyExpression
Expression<Func<TRelatedEntity,Object>>

A lambda expression representing the foreign key property(s) (t => t.Id1).

If the foreign key is made up of multiple properties then specify an anonymous type including the properties (t => new { t.Id1, t.Id2 }). The order specified should match the order of corresponding properties in HasPrincipalKey(Expression<Func<TEntity,Object>>).

Returns

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

Applies to

HasForeignKey(String[])

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

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.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceOwnershipBuilder<TEntity,TRelatedEntity> HasForeignKey (params string[] foreignKeyPropertyNames);
override this.HasForeignKey : string[] -> Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceOwnershipBuilder<'Entity, 'RelatedEntity (requires 'Entity : null and 'RelatedEntity : null)>
Public Overridable Function HasForeignKey (ParamArray foreignKeyPropertyNames As String()) As ReferenceOwnershipBuilder(Of TEntity, TRelatedEntity)

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.

Applies to