public class TaskModel
{
public int Id { get; set; }
public string Title { get; set; }
public int ParentId { get; set; }
}
[HttpDelete]
public ActionResult RemoveTask([FromBody] TaskModel taskData)
{
// var tasksIds = GetChildrenIds(taskData.id);
// Db::rawQuery($"DELETE FROM Tasks WHERE Id in {tasksIds}");
// Db.SaveChanges();
return Json(Db.Tasks);
}
private IEnumerable<int> GetChildrenIds(int parentId)
{
return Db.Tasks
.Where(task => task.Id == parentId)
.Select(task => task.Id);
}
with recursive cte (id, name, parent_id) as
(
select id,
name,
parent_id
from products
where parent_id = 19
union all
select p.id,
p.name,
p.parent_id
from products p
inner join cte
on p.parent_id = cte.id
)
select * from cte;