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; }

}
4

1 回答 1

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; }
    }
于 2013-02-18T22:51:53.993 回答