Я хочу использовать Container.CreateTransactionlBatch для операции массовой вставки. В настоящее время я делаю это с помощью метода container.CreateItemAsyn c, который требует больше времени.
Можно ли заменить container.CreateItemAsyn c на Container.CreateTransactionalBatch?
private async Task AddSubscription(EnableOrDisableSubscriptionCommand command, SubscriptionAction subscriptionAction, IList<int> notificationCategoryTypes)
{
List<Task> bulkOperations = new List<Task>();
foreach (var notificationCategory in notificationCategoryTypes)
{
var notificationTypes = Utility.GetNotificationTypes((NotificationCategoryType)notificationCategory);
foreach (var notificationType in notificationTypes)
{
foreach (var payerAccountSubscriptions in command.Subscriptions)
{
if (payerAccountSubscriptions.AccountNumbers?.Any() ?? false)
{
foreach (var accountNumber in payerAccountSubscriptions.AccountNumbers.Where(a => !string.IsNullOrEmpty(a)))
{
bulkOperations.Add(_repository.Create(subscriptionAction, notificationType,
payerAccountSubscriptions.ColCoId, payerAccountSubscriptions.PayerNumber, accountNumber, command.UserRole,
command.UserId));
}
}
else
{
bulkOperations.Add(_repository.Create(subscriptionAction, notificationType,
payerAccountSubscriptions.ColCoId, payerAccountSubscriptions.PayerNumber, null, command.UserRole,
command.UserId));
}
}
}
}
await Task.WhenAll(bulkOperations);
}
public async Task<ItemResponse<Subscription>> Create(SubscriptionAction subscriptionAction, NotificationType notificationType,
int colCoId, string payerNumber, string accountNumber, UserRole userRole, string userId, string cardId = null)
{
var eventType = Utility.GetEventType(notificationType);
var subscriptionBase = new Subscription
{
Id = Guid.NewGuid(),
IsActive = true,
Action = subscriptionAction,
ActionDesc = subscriptionAction.ToString(),
Version = (int)SubscriptionVersion.V2,
NotificationType = notificationType,
NotificationTypeDesc = notificationType.ToString(),
EventType = eventType,
EventTypeDesc = eventType.ToString(),
ColCoId = colCoId,
PayerNumber = payerNumber,
AccountNumber = accountNumber,
CardId = cardId,
DistributionGroups = new List<string> { userRole.ToString() },
DistributionUserIds = new List<string> { userId }
};
return await CreateItemAsync(subscriptionBase);
}
public async Task<ItemResponse<T>> CreateItemAsync(T item)
{
return await _container.CreateItemAsync<T>(item);
}