Share via


ReferenceCollectionBuilder<TPrincipalEntity,TDependentEntity>.HasForeignKey 方法

定義

多載

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

設定屬性 () 做為此關聯性的外鍵。

HasForeignKey(String[])

設定屬性 () 做為此關聯性的外鍵。

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

設定屬性 () 做為此關聯性的外鍵。

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceCollectionBuilder<TPrincipalEntity,TDependentEntity> HasForeignKey (System.Linq.Expressions.Expression<Func<TDependentEntity,object>> foreignKeyExpression);
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceCollectionBuilder<TPrincipalEntity,TDependentEntity> HasForeignKey (System.Linq.Expressions.Expression<Func<TDependentEntity,object?>> foreignKeyExpression);
override this.HasForeignKey : System.Linq.Expressions.Expression<Func<'DependentEntity, obj>> -> Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceCollectionBuilder<'PrincipalEntity, 'DependentEntity (requires 'PrincipalEntity : null and 'DependentEntity : null)>
Public Overridable Function HasForeignKey (foreignKeyExpression As Expression(Of Func(Of TDependentEntity, Object))) As ReferenceCollectionBuilder(Of TPrincipalEntity, TDependentEntity)

參數

foreignKeyExpression
Expression<Func<TDependentEntity,Object>>

Lambda 運算式,表示外鍵屬性 () (post => post.BlogId) 。

如果外鍵是由多個屬性所組成,請指定匿名型別,包括屬性 (comment => new { comment.BlogId, comment.PostTitle }) 。 指定的順序應該符合 中 HasPrincipalKey(Expression<Func<TPrincipalEntity,Object>>) 對應屬性的順序。

傳回

相同的產生器實例,以便鏈結多個組態呼叫。

備註

如果未 HasPrincipalKey(Expression<Func<TPrincipalEntity,Object>>) 指定 ,則會嘗試根據主體實體類型的主鍵,比對外鍵屬性的資料類型和順序。 如果它們不相符,形成唯一索引的新陰影狀態屬性將會新增至主體實體類型,作為參考索引鍵。 陰影狀態屬性是實體類別中沒有對應屬性的屬性。 屬性的目前值會儲存在 中 ChangeTracker ,而不是儲存在實體類別的實例中。

適用於

HasForeignKey(String[])

設定屬性 () 做為此關聯性的外鍵。

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceCollectionBuilder<TPrincipalEntity,TDependentEntity> HasForeignKey (params string[] foreignKeyPropertyNames);
override this.HasForeignKey : string[] -> Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceCollectionBuilder<'PrincipalEntity, 'DependentEntity (requires 'PrincipalEntity : null and 'DependentEntity : null)>
Public Overridable Function HasForeignKey (ParamArray foreignKeyPropertyNames As String()) As ReferenceCollectionBuilder(Of TPrincipalEntity, TDependentEntity)

參數

foreignKeyPropertyNames
String[]

外鍵屬性的名稱 () (s) 。

傳回

相同的產生器實例,以便鏈結多個組態呼叫。

備註

如果實體類型上沒有指定的屬性名稱 (s) ,則會將新的陰影狀態屬性新增 (s) 作為外鍵。 陰影狀態屬性是實體類別中沒有對應屬性的屬性。 屬性的目前值會儲存在 中 ChangeTracker ,而不是儲存在實體類別的實例中。

如果未 HasPrincipalKey(Expression<Func<TPrincipalEntity,Object>>) 指定 ,則會嘗試根據主體實體類型的主鍵,比對外鍵屬性的資料類型和順序。 如果它們不相符,形成唯一索引的新陰影狀態屬性將會新增至主體實體類型,作為參考索引鍵。

適用於