0
我想配置ApplicationUser
表和User
表之間的'一對一或一個'關係,其中ApplicationUser
表是主體,學生是從屬。但是,我希望有一個單獨的Primary key
表Student
表和Foreign Key
,其中引用ApplicationUser
表的ApplicationUserID
。MVC 5代碼第一個實體框架可選關係從FK分離PK
public class Student
{
[Key]
[Required]
[StringLength(10)]
public string StudentCode { get; set; }
[Required]
[StringLength(15)]
[Column(TypeName = "varchar")]
public string ContactNum { get; set; }
public virtual ApplicationUser User { get; set; }
[ForeignKey("User")]
public string ApplicationUserID { get; set; }
}
public class ApplicationUser : IdentityUser
{
public virtual Students Students { get; set; }
}
我有問題,這個遷移代碼作爲它提出了一個錯誤:
Student_User_Source:多重不是在關係中的作用「Student_User_Source「Student_User」有效。因爲「依賴角色」屬性不是關鍵屬性,所以「依賴角色」的多重性的上界必須爲「*」。
那麼如何配置呢?