Search code examples
c#odatabreezeolingo

Delete all related OData entities in one request from client


To use the Northwind database as an example, each Customer has a collection of Orders. I would like to remove all of the references between a particular Customer and all their Orders in just one request.

It looks like I can do this (based on the spec) with DELETE http://services.odata.org/V4/Northwind/Northwind.svc/Customers('ANTON')/Orders but I'm wondering if client libraries support this.

I'm using Microsoft.OData.Client for a C# client library, Apache Olingo (v4) for Java, and BreezeJS for JavaScript. An example in any of these would be much appreciated.

EDIT: Clarified that I am just removing references, not actually deleting the entities themselves.


Solution

  • Given the previous clarifications to this question that you wish to remove the references and not the entities themselves, the answer appears to be no, you cannot do what you want to do.

    In OData 4 (the specification you link to), references are obtained using $ref rather than addressing the entity directly. As a result the link you are interested in is this one:

    http://services.odata.org/V4/Northwind/Northwind.svc/Customers('ANTON')/Orders/$ref
    

    Unfortunately you can't do what you want, as the protocol says (improved for grammar):

    Resource paths addressing a single entity reference can be used in DELETE requests to unrelate two entities. Resource paths addressing a collection of references can be used in DELETE requests if they are followed by the system query option $id identifying one of the entity references in the collection.

    The specification writers have gone to some trouble to remove the operation you wish to perform from the protocol. You must DELETE each reference in turn, you can't delete a whole collection of references in one protocol request.