首先,我想說明我確實看到這個問題A LOT。我瞭解可能存在重複,但我已搜索和搜索,但我沒有找到正確的解決方案。實體框架ForeignKey問題
public class Members
{
public enum Statuses
{
APPLIED,
ACTIVE,
SUSPENDED,
DELETED
}
[Key]
public int ID { get; set; }
[Required]
public string UName { get; set; }
public int RecruiterID { get; set; }
public int AuditorID { get; set; }
public virtual ICollection<AuditorComments> AuditorComments { get; set; }
[Required]
public Statuses Status { get; set; }
[Timestamp]
public Byte[] Timestamp { get; set; }
[ForeignKey("RecruiterID")]
public virtual Members Recruiter { get; set; }
[ForeignKey("AuditorID")]
public virtual Members Auditor { get; set; }
}
基本上我是把外鍵綁在一起吧?
這裏是我收到的錯誤:
Unable to determine the principal end of an association between the types
'tn.Data.Members' and 'tn.Data.Members'. The principal end of this association
must be explicitly configured using either the relationship fluent API or data
annotations.
我有很多其他表這樣的,但如果我能得到這一個工作,那麼我就能夠解決他們所有。
招聘人員和審計人員都屬於會員類型?這是如何工作的? –
@AlaaMasoud在本網站的前一版本中,我只是在mysql中使用JOIN做到了這一點。但我現在將網站從php遷移到ASP.Net並升級網站。所以基本上這個表格爲社區擁有'會員'。每個「會員」可以有一個「招聘人員」,他顯然也是一個「會員」,但是處於領導型角色。我不必這樣做。我只希望能夠運行1個查詢,並獲取成員的信息,以及他們的招聘人員的一些信息(如UNAME) – SnareChops