0
public class UserCommentry
{
[Key]
public int ID { get; set; }
[ForeignKey("AccountID")]
public int AccountID { get; set; }
public virtual Account account { get; set; }
public Int64 TransferID { get; set; }
}
主鍵字段如何處理外鍵關係實體框架MVC
public class Account
{
[Key]
public int ID { get; set; }
public int code{ get; set; }
public Int64 TransferID { get; set; }
錯誤:
The property 'AccountID' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection where T is a valid entity type.
你已經把'ForeignKey'屬性放在錯誤的地方。只需將其移至「帳戶」屬性的正上方即可。 –