2013-02-18 103 views
1

可以說我有一個User模型,現在我想添加一個Friend模型。我想命名我的FK字段RequestorIDResponderID。什麼數據註釋或流利的api映射我需要做到這一點,並防止EF自動生成自己的列?用兩個外鍵創建模型到同一個表

public class Friend 
{ 
    public int FriendID { get; set; } 
    public int RequestorID { get; set; } 
    public int ResponderID { get; set; } 
    public int FriendStatusID { get; set; } 
    public DateTime User1RequestDate { get; set; } 
    public DateTime User2ResponseDate { get; set; } 
    public virtual FriendStatus FriendStatus { get; set; } 


    public virtual User Requestor { get; set; } 
    public virtual User Responder { get; set; } 

} 

回答

2

試試這個

public class Friend 
    { 
     public int FriendID { get; set; } 
     public int RequestorID { get; set; } 
     public int ResponderID { get; set; } 
     public int FriendStatusID { get; set; } 
     public DateTime User1RequestDate { get; set; } 
     public DateTime User2ResponseDate { get; set; } 
     public virtual FriendStatus FriendStatus { get; set; } 

     [ForeignKey("RequestorID")] //fixed 
     public virtual User Requestor { get; set; } 
     [ForeignKey("ResponderID")] 
     public virtual User Responder { get; set; } 
    } 
+0

您對第一個數據註釋語法錯誤,但工作。謝謝。 – 2013-02-18 23:24:14

相關問題