/// <summary> /// Deletes the threads matching the passed in filter, inside the transaction specified. /// </summary> /// <param name="threadFilter">The thread filter.</param> /// <param name="trans">The transaction to use.</param> private static void DeleteThreads(PredicateExpression threadFilter, Transaction trans) { // we've to perform a set of actions in a given order to make sure we're not violating FK constraints in the DB. // delete messages in thread MessageManager.DeleteAllMessagesInThreads(threadFilter, trans); // delete bookmarks (if exists) of the threads to be deleted BookmarkCollection bookmarks = new BookmarkCollection(); trans.Add(bookmarks); // use again a fieldcompareset predicate bookmarks.DeleteMulti(new FieldCompareSetPredicate(BookmarkFields.ThreadID, ThreadFields.ThreadID, SetOperator.In, threadFilter)); // delete audit info related to this thread. Can't be done directly on the db due to the fact the entities are in a TargetPerEntity hierarchy, which // can't be deleted directly on the db, so we've to fetch the entities first. AuditDataThreadRelatedCollection threadAuditData = new AuditDataThreadRelatedCollection(); trans.Add(threadAuditData); // use a fieldcompareset predicate filter, based on the threadFilter. threadAuditData.GetMulti(new FieldCompareSetPredicate(AuditDataThreadRelatedFields.ThreadID, ThreadFields.ThreadID, SetOperator.In, threadFilter)); threadAuditData.DeleteMulti(); // delete support queue thread entity for this thread (if any) SupportQueueThreadCollection supportQueueThreads = new SupportQueueThreadCollection(); trans.Add(supportQueueThreads); // use again a fieldcompareset predicate supportQueueThreads.DeleteMulti(new FieldCompareSetPredicate(SupportQueueThreadFields.ThreadID, ThreadFields.ThreadID, SetOperator.In, threadFilter)); // delete threadsubscription entities ThreadSubscriptionCollection threadSubscriptions = new ThreadSubscriptionCollection(); trans.Add(threadSubscriptions); // use again a fieldcompareset predicate threadSubscriptions.DeleteMulti(new FieldCompareSetPredicate(ThreadSubscriptionFields.ThreadID, ThreadFields.ThreadID, SetOperator.In, threadFilter)); // delete the threads ThreadCollection threads = new ThreadCollection(); trans.Add(threads); // we already have the filter to use, namely the filter passed in. threads.DeleteMulti(threadFilter); // don't commit the transaction, that's up to the caller. }