I have a TaskItem class that has child items of the same type:
public class TaskItem
{
public Guid Id { get;set; }
// Parent Task
public TaskItem ParentTask { get; set; }
public Guid? ParentTaskId { get; set; }
//Child Tasks
public ICollection<TaskItem > ChildTasks{ get; set; }
}
To get a Task and its subtasks recursively as a Flat list:
var taskList = taskDBContext.TaskItems.Include(c => c.ChildTasks)
.Where(x => x.Id == taskId)
.SelectMany(x => x.ChildTasks)
.ToList();
The issue is that I always get a single task though the task has many grandchildren at various levels. My scenario is loading a specific parent and its children and grandchildren as a single list.
Also, please let me know if this is a good design or do I have to change it.