C#C
C#3y ago
v0fbu1vm

❔ Linq Query HELP

I have this entity. During deletion, I would like to load all related entities, so that I can delete them also. Here is the entity
/// <summary>
///     Represents a comment entity.
/// </summary>
public class Comment : AbstractEntity, ISuspension
{
    public required string Content { get; set; }
    public int Depth { get; set; }
    public Guid AuthorId { get; set; }
    public virtual User Author { get; set; } = default!;
    public Guid QuoteId { get; set; }
    public virtual Quote Quote { get; set; } = default!;
    public Guid? ParentId { get; set; }
    public virtual Comment ParentComment { get; set; } = default!;
    public virtual ICollection<Comment> Replies { get; set; } = new HashSet<Comment>();
    public virtual ICollection<Like<Comment>> Likes { get; set; } = new HashSet<Like<Comment>>();
    public virtual ICollection<Dislike<Comment>> Dislikes { get; set; } = new HashSet<Dislike<Comment>>();
    public virtual ICollection<Suspension<Comment>> Suspensions { get; set; } = new HashSet<Suspension<Comment>>();
    public bool IsSuspended { get; set; }
}
I have come this far
var comment = await DbContext.Comments
            .Include(x => x.Replies)
            .ThenInclue(x => x.Likes)
            .ThenInclue(x => x.Dislikes)
            .ThenInclue(x => x.Suspensions)
            .Include(x => x.Likes)
            .Include(x => x.Dislikes)
            .Include(x => x.Suspensions)
            .FirstOrDefaultAsync(x => x.Id == request.Id && x.AuthorId == UserId, cancellationToken);
I would like to load the Replies, and there likes, dislikes, suspensions. I also need to load the replies of replies and there likes, dislikes, suspensions etc. Any help would be appreciated. I don't think this query will do the job.
Was this page helpful?