我有这个评论模型,每个评论都可以是其他评论的答案。
public class Comment
{
public virtual int Id { get; set; }
public virtual string Body { get; set; }
public virtual DateTime? AddedDate { get; set; }
public virtual bool IsApproved { get; set; }
public virtual int LikeCount { get; set; }
public virtual User User { get; set; }
public virtual AnonymousUser AnonymousUser { get; set; }
public virtual Post Post { get; set; }
public virtual Page Page { get; set; }
public virtual int? ParentId { get; set; }
public virtual Comment Parent { get; set; }
public ICollection<Comment> Children { get; set; }
public virtual byte[] RowVersion { get; set; }
}
我尝试使用此代码来获取“IsApproved==true”的评论
this._comments
.Where(comment => comment.Post.Id == postId).Include(comment => comment.User)
.Include(comment => comment.AnonymousUser)
.Include(comment => comment.Children).Where(comment => comment.IsApproved == true)
.OrderBy(comment => comment.AddedDate)
.Skip(page * count)
.Take(count).ToList()
.Where(comment => comment.Parent == null).ToList();
但是这个查询只返回“IsApproved==true”的根注释。
我应该怎么做才能过滤所有评论,甚至是孩子。
谢谢