rest - What strategies exist to accomplish transactions over an OData service layer? -


consider following example:

an odata service layer exposes order , orderline resources. consumer retrieves order , related orderlines. consumer edits order, edits 1 orderline, deletes 1 orderline , creates 1 orderline. how can consumer save of these changes ensuring changes or nothing?

from understand of odata, sent several service calls:

put /api/order/9999
put /api/orderline/1001
delete /api/orderline/1002
post /api/orderline/1002

each call stateless , independent , server not able determine when begin , end transaction.


i've considered various solutions i'm not sure of them work:

solution 1) have order resource contain orderline information. solution single service call made "put /api/order/9999" contain of orderline changes. strategy seems because abstracts consumer transaction details on server. however, can't find way include orderline collection order entity when putting both breeze , wcf data services client. also, i'm not sure how deleting orderline communicated in order. there in odata specification accomplish this? found it's possible post related entities in section 10.3.2.2 of spec. have not found similar creating/updating/deleting related entities when putting entity.

solution 2) using odata's $batch operation send 4 service calls one. i'm not sure if intention of $batch feature performance or grouping related service calls transaction. using $batch transactions, responsibility of consumer determine service calls send in same batch. proper separation of concerns? on server side, batch handler might complicated. if there validation needed occur between order , orderline batch handler need recompose these objects , validate them before attempting database transactions.

solution 3) expose begin , end transaction service calls. again, exposing implementation details consumer. think implications pretty similar solution 2.

the solution must work on .net 4.0 , service calls must work both .net , javascript clients. scalability not concern. using "web api odata" never support $batch feature in .net 4.0 changing on "wcf data services" possibility. chose odata it's retrieve features if transactions cud operations work better without odata i'm open suggestions. 1 possibility continue using odata application's advanced search screens use regular rest services cud.

a batch work 4 four operations send if using wcf data services. ef built-in implementation wcf data services make changes in ef operation context before invoking savechanges, or nothing if savechanges call fails, emulating behavior of transaction.


Comments