假设我有User
模型,现在我想添加Friend
模型。我想命名我的FK字段RequestorID
和ResponderID
。我需要使用哪些数据注释或流畅的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; }
}
答案 0 :(得分: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; }
}