Skip to content
Jason Finch edited this page Aug 23, 2018 · 12 revisions

OData supports deletions only by resource key, so in case the entry is identified by non-key properties or multiple entries should be deleted, corresponding entry keys should first be retrieved on a client side and only then Delete request can be invoked for each key value. Simple.OData.Client simplifies non-key and multiple entry deletion by supporting passing an OData filter expression to a delete operation. Bear in mind however that filter-based deletions will typically result in execution of multiple OData requests.


Delete a product by key

Untyped syntax

await client
    .For("Products")
    .Key(1)
    .DeleteEntryAsync();

Typed syntax

await client
    .For<Products>()
    .Key(1)
    .DeleteEntryAsync();

Dynamic syntax

var x = ODataFilter.Expression;
await client
    .For(x.Products)
    .Key(1)
    .DeleteEntryAsync();

Request URI: DELETE Products(1)


Delete multiple products

Untyped syntax

await client
    .For("Products")
    .Filter("length(ProductName)+eq+4")
    .DeleteEntriesAsync();

Typed syntax

await client
    .For<Products>()
    .Filter(x => x.ProductName.Length() == 4)
    .DeleteEntriesAsync();

Dynamic syntax

var x = ODataFilter.Expression;
await client
    .For(x.Product)
    .Filter(x.ProductName.Length() == 4)
    .DeleteEntriesAsync();

Request URI: N/A (separate DELETE request for each entry matching search criteria)


See also:
Modifying data