2014-07-15 52 views
1

通常,ODataController设置为处理一个底层DB实体的CRUD和其他操作。例如,当您更新一个或多个客户订单时,这很有效。使用ODataControllers的交易

但是,如何在一次交易中将更改提交给两个或多个实体 - 例如,用多个相关客户订单详细信息更新客户订单?这可以(或者应该这样)使用一个ODataController来完成吗?或者,将服务组件放在包装整个事务的ODataControllers之上会更好吗?

回答

0

批处理功能旨在处理一个http请求中的多个操作。批处理请求如下所示:

POST /service/$batch HTTP/1.1 
Host: host 
OData-Version: 4.0 
Content-Type: multipart/mixed;boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b 

--batch_36522ad7-fc75-4b56-8c71-56071383e77b 
Content-Type: multipart/mixed;boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd 

--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd 
Content-Type: application/http 
Content-Transfer-Encoding: binary 
Content-ID: 1 

POST /service/Customers HTTP/1.1 
Host: host 
Content-Type: application/atom+xml;type=entry 
Content-Length: ### 

<AtomPub representation of a new Customer> 
--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd 
Content-Type: application/http 
Content-Transfer-Encoding: binary 
Content-ID: 2 

POST $1/Orders HTTP/1.1 
Host: host 
Content-Type: application/atom+xml;type=entry 
Content-Length: ### 

<AtomPub representation of a new Order> 
--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd-- 
--batch_36522ad7-fc75-4b56-8c71-56071383e77b-- 

每个ChangeSet都必须视为事务。 以下是供您参考的样本:http://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v3/ODataEFBatchSample/

+0

非常感谢您的有用评论,并且链接非常好! – stickian