private async Task ExecuteChangeset(IReadOnlyList <OeOperationMessage> changeset, CancellationToken cancellationToken) { Object dataContext = null; try { dataContext = _dataAdapter.CreateDataContext(); foreach (OeOperationMessage operation in changeset) { AddToEntitySet(dataContext, operation); } await _dataAdapter.SaveChangesAsync(_model, dataContext, cancellationToken).ConfigureAwait(false); } finally { if (dataContext != null) { _dataAdapter.CloseDataContext(dataContext); } } }
public void OnActionExecuted(ActionExecutedContext context) { if (!(context.ModelState is BatchModelStateDictionary) && _asyncLocal.Value is BatchModelStateDictionary modelState) { //single operation _asyncLocal.Value = new ModelStateDictionary(); Db.OeDataAdapter dataAdapter = modelState.DataAdapter; Object dataContext = modelState.DataContext.DbContext; OeOperationMessage operation = modelState.DataContext.Operation; try { dataAdapter.SaveChangesAsync(dataContext, CancellationToken.None).GetAwaiter().GetResult(); dataAdapter.EntitySetAdapters.Find(operation.EntitySet).UpdateEntityAfterSave(dataContext, operation.Entry); context.HttpContext.Response.ContentType = context.HttpContext.Request.ContentType; var batchWriter = new Writers.OeBatchWriter(modelState.DataContext.EdmModel, UriHelper.GetBaseUri(context.HttpContext.Request)); batchWriter.WriteOperationAsync(context.HttpContext.Response.Body, operation).GetAwaiter().GetResult(); } finally { dataAdapter.CloseDataContext(dataContext); } } }