与OData的事务批处理 [英] Transactional batch processing with OData

查看:474
本文介绍了与OData的事务批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Web API的OData的工作,我有$批量处理的工作,但是,持久化到数据库不是事务性的。如果我包括一个修改多个请求在我的要求下,这些项目中的一个出现故障,另一个仍然完成,因为到控制器的每个单独调用都有它自己的DbContext。

Working with Web API OData, I have $batch processing working, however, the persistence to the database is not Transactional. If I include multiple requests in a Changeset in my request, and one of those items fails, the other still completes, because each separate call to the controller has it's own DbContext.

例如,如果我提交批处理有两个变化集:

for example, if I submit a Batch with two change sets:

1批
  - 变更1
  - - 补丁有效的对象
  - - 补丁无效的对象
  - 完变更集1
  - 2变更
  - - 插入有效的对象
  - 完变更2
结束批处理

Batch 1 - ChangeSet 1 - - Patch valid object - - Patch invalid object - End Changeset 1 - ChangeSet 2 - - Insert Valid Object - End ChangeSet 2 End Batch

我想到的是,第一个有效的补丁将然而回滚,由于变更集可能无法全部完成,因为每次调用都有自己的DbContext,第一个补丁承诺,二是没有了,插入承诺。

I would expect that the first valid patch would be rolled back, as the change set could not be completed in its entirety, however, since each call gets its own DbContext, the first Patch is committed, the second is not, and the insert is committed.

有通过与OData的一个$一批请求支持事务的标准方式吗?

Is there a standard way to support transactions through a $batch request with OData?

推荐答案

以下链接将显示需要处理的事务的变更在Web API的OData实现。你是正确的,默认的批量处理程序不会为你做这一点:

The following link shows the Web API OData implementation that is required to process the changeset in transactions. You are correct that the default batch handler does not do this for you:

http://aspnet.$c$cplex.com/SourceControl/latest#Samples/WebApi/OData/v3/ODataEFBatchSample/

这篇关于与OData的事务批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆