ReferenceReferenceBuilder<TEntity,TRelatedEntity>.HasForeignKey Method

Definition

Overloads

HasForeignKey(String, String[])

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

HasForeignKey(Type, String[])

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

HasForeignKey<TDependentEntity>(String[])

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

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

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

HasForeignKey(String, String[])

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

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

Parameters

dependentEntityTypeName
String

The name of entity type that is the dependent in this relationship (the type that has the foreign key properties).

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, 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

HasForeignKey(Type, String[])

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

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

Parameters

dependentEntityType
Type

The entity type that is the dependent in this relationship (the type that has the foreign key properties).

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(Type, 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

HasForeignKey<TDependentEntity>(String[])

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

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

Type Parameters

TDependentEntity

The entity type that is the dependent in this relationship (the type that has the foreign key properties).

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<TPrincipalEntity>(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 referenced key.

Applies to

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

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

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

Type Parameters

TDependentEntity

The entity type that is the dependent in this relationship. That is, the type that has the foreign key properties.

Parameters

foreignKeyExpression
Expression<Func<TDependentEntity,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 keys in HasPrincipalKey<TPrincipalEntity>(Expression<Func<TPrincipalEntity,Object>>).

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<TPrincipalEntity>(Expression<Func<TPrincipalEntity,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.

Applies to