public async Task <int> DeleteAsync(string id, CancellationToken cancellationToken = default) { var definitionRecords = await _workflowDefinitionVersionRepository.GetListByDefinitionIdAndVersionAsync(id, VersionOptions.All, true, cancellationToken); var instanceRecords = await _workflowInstanceRepository.GetListByDefinitionIdAsync(id, false, cancellationToken); var activityDefinitionRecords = await _activityDefinitionRepository .GetListByWorkFlowInstanceDefinitionIdAsync(id, cancellationToken : cancellationToken); var connectionRecords = await _workflowDefinitionVersionRepository .GetConnectionDefinitionListByWorkFlowInstanceDefinitionIdAsync(id, cancellationToken : cancellationToken); var activityInstanceRecords = await _activityInstanceRepository .GetListByWorkFlowInstanceDefinitionIdAsync(id, cancellationToken : cancellationToken); var blockingActivityRecords = await _workflowInstanceRepository .GetBlockingActivityListByWorkFlowInstanceDefinitionIdAsync(id, cancellationToken : cancellationToken); _workflowInstanceRepository.BatchDeleteWorkflowInstances(instanceRecords); _workflowDefinitionVersionRepository.BatchDeleteWorkflowDefinitionVersions(definitionRecords); _activityDefinitionRepository.BatchDeleteActivityDefinitions(activityDefinitionRecords); _workflowDefinitionVersionRepository.BatchDeleteConnectionDefinitions(connectionRecords); _activityInstanceRepository.BatchDeleteActivityInstances(activityInstanceRecords); _workflowInstanceRepository.BatchDeleteBlockingActivitys(blockingActivityRecords); await _unitOfWorkManager.Current.SaveChangesAsync(cancellationToken); return(definitionRecords.Count); }