In my program I am deleting subprojects using LINQ. It's incredibly slow. There is a lot of cascade on delete's here so I am deleting from multiple tables. Any help and tips would be appreciated.Here is an overview of the codeWhen you delete a subProject you must deleteActivitieswhich you must deleteActivityDocumentsActivityNotesActivityPersonsActivityPersonRolesActivityMachinesPredActivityLinksSuccActivityLinksCommunicationThreadsthreadContentTagthreadParticipantsthreadMessagesAnd each subproject can have nested subprojects with the same structure. I am looking for a faster way to do this than the code below. I plan on replacing all of those .Remove() calls with .Clear()public void DeleteSubProject(SubProject subProject){    foreach (Activity activity in subProject.Activities.ToList())    {        UnitOfWork.ActivityService.DeleteActivity(activity);    }    subProject.Activities.Clear();    foreach (SubProjectDocument subProjectDocument in subProject.SubProjectDocuments.ToList())    {        subProject.SubProjectDocuments.Remove(subProjectDocument);        UnitOfWork.SubProjectDocumentService.Delete(subProjectDocument);    }    foreach (SubProjectNote subProjectNote in subProject.SubProjectNotes.ToList())    {        subProject.SubProjectNotes.Remove(subProjectNote);        UnitOfWork.SubProjectNoteService.Delete(subProjectNote);    }    foreach (SubProjectPerson subProjectPerson in subProject.SubProjectPersons.ToList())    {        subProject.SubProjectPersons.Remove(subProjectPerson);        UnitOfWork.SubProjectPersonService.Delete(subProjectPerson);    }    foreach (SubProject childSubProject in subProject.ChildSubProjects.ToList())    {        subProject.ChildSubProjects.Remove(childSubProject);        DeleteSubProject(childSubProject);    }    Delete(subProject);}Here is deleting an activitypublic void DeleteActivity(Activity activity){    //delete documents    foreach (ActivityDocument ad in activity.ActivityDocuments.ToList())    {        activity.ActivityDocuments.Remove(ad);        UnitOfWork.ActivityDocumentService.Delete(ad);    }    //delete notes    foreach (ActivityNote an in activity.ActivityNotes.ToList())    {        activity.ActivityNotes.Remove(an);        UnitOfWork.ActivityNoteService.Delete(an);    }    //delete people    foreach (ActivityPerson ap in activity.ActivityPersons.ToList())    {       //    // the following call cascades the delete        UnitOfWork.ActivityPersonService.DeleteActivityPerson(ap);    }    activity.ActivityPersons.Clear();    foreach (CommunicationThread thread in activity.CommunicationThreads.ToList())    {        activity.CommunicationThreads.Remove(thread);        UnitOfWork.CommunicationThreadService.DeleteThread(thread);    }    //delete machines    foreach (ActivityMachine am in activity.ActivityMachines.ToList())    {        activity.ActivityMachines.Remove(am);        UnitOfWork.ActivityMachineService.Delete(am);    }    //remove pred links    foreach (ActivityLink al in activity.PredActivityLinks.ToList())    {        //activity.PredActivityLinks.Remove(al);        UnitOfWork.ActivityLinkService.Delete(al);    }    //remove succ links    foreach (ActivityLink al in activity.SuccActivityLinks.ToList())    {        //al.SuccActivity.EarliestStartDate = Project        //activity.SuccActivityLinks.Remove(al);        UnitOfWork.ActivityLinkService.Delete(al);    }    Delete(activity);}Then you have communication threadsinternal void DeleteThread(CommunicationThread communicationThread){    var threadContentTags = communicationThread.CommunicationThreadContentTags.ToList();    foreach(var threadContentTag in threadContentTags)    {        UnitOfWork.Instance.CommunicationThreadContentTagService.Delete(threadContentTag);    }    communicationThread.CommunicationThreadContentTags.Clear();    var threadParticipants = communicationThread.CommunicationThreadParticipants.ToList();    foreach (var threadParticipant in threadParticipants)    {        UnitOfWork.Instance.CommunicationThreadParticipantService.Delete(threadParticipant);    }    communicationThread.CommunicationThreadParticipants.Clear();    var threadMessages = communicationThread.CommunicationMessages.ToList();    foreach (var threadMessage in threadMessages.Where(msg => msg.CommentOnMessageID == null))    {        UnitOfWork.Instance.CommunicationMessageService.DeleteMessage(threadMessage);    }    communicationThread.CommunicationMessages.Clear();    Delete(communicationThread);}delete, we can ignore deleting threads and messages. saveChanges() is called when the save button is pushedpublic virtual void Delete(TEntity entityToDelete){    if (!CanDelete(entityToDelete)) return;    if (EntityContext.Entry(entityToDelete).State == EntityState.Detached)    {        DbSet.Attach(entityToDelete);    }    DbSet.Remove(entityToDelete);}
Delete records from multiple tables when deleting a subproject
c#;performance;linq