/// <summary> /// Begins the async save changes operation /// </summary> /// <returns></returns> public Task SaveChangesAsync() { return(asyncDocumentKeyGeneration.GenerateDocumentKeysForSaveChanges() .ContinueWith(keysTask => { keysTask.AssertNotFailed(); var cachingScope = EntitiesToJsonCachingScope(); try { var data = PrepareForSaveChanges(); return AsyncDatabaseCommands.BatchAsync(data.Commands.ToArray()) .ContinueWith(task => { try { UpdateBatchResults(task.Result, data); } finally { cachingScope.Dispose(); } }); } catch { cachingScope.Dispose(); throw; } }).Unwrap()); }
/// <summary> /// Begins the async save changes operation /// </summary> /// <returns></returns> public async Task SaveChangesAsync(CancellationToken token = default(CancellationToken)) { await asyncDocumentKeyGeneration.GenerateDocumentKeysForSaveChanges().WithCancellation(token); using (EntityToJson.EntitiesToJsonCachingScope()) { var data = PrepareForSaveChanges(); if (data.Commands.Count == 0) { return; } IncrementRequestCount(); var result = await AsyncDatabaseCommands.BatchAsync(data.Commands.ToArray(), token); UpdateBatchResults(result, data); } }