How can I load all child records recursively?
问题 I have this Project class: public class Project { public int Id { get; set; } public int? ParentId { get; set; } public List<Project> ChildProjects { get; set; } // more properties } This is my attempt to load all descendants of any given project: private async Task<List<Project>> LoadDescendantsOf(Project project) { project.ChildProjects = await db.Projects .Where(p => p.ParentId == project.Id) .ToListAsync(); foreach (Project childProject in project.ChildProjects) { yield return