Last active
November 13, 2020 05:58
-
-
Save PradeepLoganathan/3c7f9452eb3b8aa9c38c324b9650db3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task AddOrders(List<Order> orders, string customerId) | |
{ | |
var ordersToInsert = new List<KeyValuePair<PartitionKey, Stream>>(); | |
foreach (var order in orders) | |
{ | |
var stream = new MemoryStream(); | |
await JsonSerializer.SerializeAsync(stream, order); | |
ordersToInsert.Add(new KeyValuePair<PartitionKey, Stream>(new PartitionKey(order.CustomerId), stream)); | |
} | |
var parallelTasks = new List<Task>(); | |
foreach (var (key, value) in ordersToInsert) | |
{ | |
parallelTasks.Add(this._cosmosDbContext.OrdersContainer.CreateItemStreamAsync(value, key) | |
.ContinueWith(x => | |
{ | |
var response = x.Result; | |
Console.WriteLine($"Bulk insert {response.ClientRequestId} has status {response.Status} with message {response}"); | |
})); | |
} | |
await Task.WhenAll(parallelTasks); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment