0

我有一个自我参考模型。我想用 linq 获取数据。我想在状态正常时返回数据。但如果父状态正常,则所有子状态都返回正常或待处理或已删除。我怎样才能做到这一点。

var model = _efComment.List(p => p.PostId == postId);
        var list = model.ToList()
            .Where(p => p.ComentStatus == ComentStatus.Ok)
            .Where(x => x.Reply == null)
            .ToList();using System.Collections.Generic;

using System.ComponentModel.DataAnnotations.Schema;
using DomainModel.Classes;

namespace DomainModel
{
    public class Comment : BaseFieldsTables
    {
        public string Content { get; set; }
        public string WriterName { get; set; }
        public string WriterEmail { get; set; }
        public string WriterWebsite { get; set; }

        public int PostId { get; set; }

        [ForeignKey("PostId")]
        public Post Post { get; set; }

        public Comment Reply { set; get; }

        public int? ReplyId { get; set; }
        public ICollection<Comment> Children { get; set; }
        public ComentStatus ComentStatus { get; set; }
    }
}
namespace DomainModel
{
    public enum ComentStatus
    {
        Ok = 1,
        Pending = 2,
        Deleted = 3
    }
}
4

0 回答 0