Entity framework 在完全不同的表中存在INSERT语句冲突的表

Entity framework 在完全不同的表中存在INSERT语句冲突的表,entity-framework,Entity Framework,我得到以下错误 INSERT语句与外键约束“FK_dbo.NotificationObject_dbo.Comment_CommentReplyID”冲突。冲突发生在数据库“DB_f0f07b19b55c44199988352815f71b25c”表“dbo.Comment”列“CommentID”中 我很困惑,因为NotificationObject表可以有多种可选外键,包括注释键或注释回复键。当我尝试添加带有CommentReplyID的行时,它会给出上面的错误。。。关于评论表???键应该指

我得到以下错误

INSERT语句与外键约束“FK_dbo.NotificationObject_dbo.Comment_CommentReplyID”冲突。冲突发生在数据库“DB_f0f07b19b55c44199988352815f71b25c”表“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; }
}
公共类NotificationObject
{
公共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;}
公共虚拟NotificationType NotificationType{get;set;}
公共虚拟注释{get;set;}
公共虚拟注释CommentVote{get;set;}
公共虚拟注释CommentReply{get;set;}
公共虚拟注释CommentReplyNote{get;set;}
公共虚拟ActivityComment ActivityComment{get;set;}
公共虚拟ICollection NotificationActor{get;set;}
}
公开课评论
{
public int CommentID{get;set;}
public int ProjectDocID{get;set;}
public int UserID{get;set;}
公共字符串文本{get;set;}
公共字符串引号{get;set;}
public DateTime DateCreated{get;set;}
公共虚拟ICollection CommentVote{get;set;}
公共虚拟ICollection CommentReply{get;set;}
公共虚拟ICollection CommentReport{get;set;}
公共虚拟ProjectDoc ProjectDoc{get;set;}
公共虚拟用户用户{get;set;}
公共虚拟ICollection范围{get;set;}
}

为什么不让我在
NotificationObject
表中的
CommentReplyID
字段中添加一个值?

您的
CommentReply
导航属性位于
NotificationObject
目标
注释
类型,而不是
CommentReply
类型

顺便说一句。检查其他属性。是的,刚刚修复了所有这些,呵呵。哎呀!