public static void DeleteChilds(this IRepository<School> sc, int schoolId) { var studentsRepo = new EfRepository<Student>(new SchoolContext()); var studentsFromSchool = studentsRepo.All().Where(x => x.School.SchoolId == schoolId).ToList(); foreach (Student student in studentsFromSchool) { studentsRepo.DeleteChilds(student.School.SchoolId); studentsRepo.Delete(student.StudentId); } }