删除线程中的评论回复的最佳方法

时间:2017-03-15 19:38:11

标签: c# asp.net-mvc ef-code-first cascading-deletes threaded-comments

我正在开发一个带有线程评论系统的项目(Asp.Net MVC CodeFirst)。

这是评论模型:

public class Comment : EntityBase {

    public string FirstName { get; set; }
    public string Email { get; set; }
    public string Body { get; set; }
    public int? ParentID { get; set; }
    public bool HasChild { get; set; }

    // Association Handling
    [ForeignKey("Post")]
    public virtual int PostID { get; set; }
    public virtual Post Post { get; set; }
    public virtual Comment CommentReference { get; set; }
}

并在OnModelCreating()方法中:

protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<Comment>()
            .HasOptional(c => c.CommentReference)
            .WithMany()
            .HasForeignKey(c => c.ParentID);

        // Here I can't set cascade on delete to true (cause of cycle)
        //.WillCascadeOnDelete(true);
}

问题是如何通过传递评论的(Id)来删除评论中的评论?

0 个答案:

没有答案