1. 程式人生 > 實用技巧 >EFcore兩個實體兩個一對多關係實現問題探討

EFcore兩個實體兩個一對多關係實現問題探討

最近從.NET Framework 轉寫一個EFCore,原來的實體模型不能用,用Code First發現這個問題,

存在兩個實體

AppuUser類

Account類

兩個實體存在兩隊一對多關係,即一個使用者擁有多個賬戶,一個使用者可以Check多個賬戶,在Account內增加兩個標量外來鍵和導航屬性,在Appusr內增加兩個Icollection導航屬性。

以上,執行Add Migration時發現無法確定Account.Appuser Owner的外來鍵關係。報錯:Unable to determine the relationship represented by navigation property 'Account.Owner' of type 'AppUser'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

那麼如何打FK標籤屬性才能正確讓EFCore確認關係呢