0

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

这是评论模型:

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)

4

0 回答 0