-
Notifications
You must be signed in to change notification settings - Fork 213
Deleting entries
Simple.Data method Delete is used to create new entries in OData collections.
OData supports deletions only by resource key, so in case the entry is identified by non-key properties, the adapter first issue HTTP GET request to retrieve entry's key value and then invokes HTTP DELETE request with the key value.
var product = _db.Products.Insert(ProductName: "Test1", UnitPrice: 18m); product = _db.Products.FindByProductName("Test1"); Assert.NotNull(product); _db.Products.Delete(ProductName: "Test1"); product = _db.Products.FindByProductName("Test1"); Assert.Null(product);
Request URI: GET Products?$filter=ProductName+eq+%27Test1%27
Request URI: DELETE Products(84)
Sending the whole object to Simple.Data Delete command results in not very efficient OData command because OData adapter receives Delete argument as a Simple.Data SimpleExpression object with all entry properties joined as a search condition. See below how large is a request URI.
var product = _db.Products.Insert(ProductName: "Test2", UnitPrice: 18m); product = _db.Products.FindByProductName("Test2"); Assert.NotNull(product); _db.Products.Delete(product); product = _db.Products.FindByProductName("Test2"); Assert.Null(product);
Request URI: GET Products?$filter=(ProductID+eq+85+and+(SupplierID+eq+null+and+(CategoryID+eq+null+and+(ProductName+eq+%27Test2%27+and+(EnglishName+eq+null+and+(QuantityPerUnit+eq+null+and+(UnitPrice+eq+18+and+(UnitsInStock+eq+null+and+(UnitsOnOrder+eq+null+and+(ReorderLevel+eq+null+and+Discontinued+eq+false))))))))))
Request URI: DELETE Products(85)
See also:
Modifying data
Simple.Data documentation for Delete