public async Task DeleteBulkAsync <T>(List <string> ids) where T : MasterDocument { if (ids?.Count <= 0) { new ArgumentNullException(nameof(ids)); } var firstId = ids.First(); if (firstId.IsNullOrEmpty()) { throw new ArgumentNullException($"First id {nameof(firstId)}.", ids.GetType().Name); } var partitionId = firstId.IdToMasterPartitionId(); double totalRU = 0; try { var partitionKey = new Cosmos.PartitionKey(partitionId); var concurrentTasks = new List <Task>(ids.Count); foreach (var id in ids) { concurrentTasks.Add(container.DeleteItemAsync <T>(id, partitionKey) .ContinueWith(async(responseTask) => { if (responseTask.Exception != null) { logger.Error(responseTask.Exception); } totalRU += (await responseTask).RequestCharge; })); } await Task.WhenAll(concurrentTasks); } catch (Exception ex) { throw new CosmosDataException(partitionId, ex); } finally { logger.Metric($"CosmosDB RU, @master - delete bulk count '{ids.Count}' type '{typeof(T)}'.", totalRU); } }
static async Task DeleteItem(string id) { var response = await container.DeleteItemAsync <Film>(id, new PartitionKey("/Country")); }
async static Task DeleteAppAsync() { var result = await _container.DeleteItemAsync <object>("87cca0bb-76cb-49ba-ab49-e1f393d9fbaa", new PartitionKey("Business")); Console.WriteLine(result.StatusCode); }
public async Task DeleteItemAsync(string id) { await _container.DeleteItemAsync <T>(id, ResolvePartitionKey(id)); }