我收到以下错误。
INSERT语句与FOREIGN KEY约束“FK_dbo.NotificationObject_dbo.Comment_CommentReplyID”冲突。冲突发生在数据库“DB_f0f7b19b55c44199988352815f71b25c”,表“dbo.Comment”,列“CommentID”。
我很困惑,因为NotificationObject
表可以有多种可选的外键,包括注释的键或注释的回复。当我尝试添加一个CommentReplyID
的行时,它会给出上面的错误...关于注释表???键应该指向CommentReply
表,所以我很困惑。
请参阅下面的相关模型。
public class NotificationObject
{
public int ID { get; set; }
public int NotificationTypeID { get; set; }
public int? CommentID { get; set; }
public int? CommentVoteID { get; set; }
public int? CommentReplyID { get; set; }
public int? CommentReplyVoteID { get; set; }
public int? UserID { get; set; }
public int? ActivityCommentID { get; set; }
public DateTime DateCreated { get; set; }
public virtual NotificationType NotificationType { get; set; }
public virtual Comment Comment { get; set; }
public virtual Comment CommentVote { get; set; }
public virtual Comment CommentReply { get; set; }
public virtual Comment CommentReplyVote { get; set; }
public virtual ActivityComment ActivityComment { get; set; }
public virtual ICollection<NotificationActor> NotificationActor { get; set; }
}
public class Comment
{
public int CommentID { get; set; }
public int ProjectDocID { get; set; }
public int UserID { get; set; }
public string text { get; set; }
public string quote { get; set; }
public DateTime DateCreated { get; set; }
public virtual ICollection<CommentVote> CommentVote { get; set; }
public virtual ICollection<CommentReply> CommentReply { get; set; }
public virtual ICollection<CommentReport> CommentReport { get; set; }
public virtual ProjectDoc ProjectDoc { get; set; }
public virtual User User { get; set; }
public virtual ICollection<ranges> ranges { get; set; }
}
为什么不让它为CommentReplyID
表中的NotificationObject
字段添加值?
答案 0 :(得分:2)
CommentReply
中的NotificationObject
导航属性定位Comment
类型,而不是CommentReply
类型。