Reputation: 99
How do I delete an entity that is not tracked by DataServiceContext. For instance, I have an object of my entity in the client side and I want to delete it. I know this particular object is already present inside the database in server side, but it is not inside the DataServiceContext entity tracker (one of the reason could be this object was not added by my client). How do i delete this object. Kindly help me
Upvotes: 2
Views: 607
Reputation: 99
[Answering my own question]
This is how I am doing at present. Let's say My Entity is as below
class Book
{
public string ISBN {get; set;}
public string Name {get; set;}
}
I want to delete a book whose ISBN (key property) is "AXBX".
var container = new Container(new Uri("http://localhost/MyApp/odata"));
var book = new Book(){ISBN = "AXBX"}
container.AttachTo("Books", book); // add object to entity tracker
container.DeleteObject(book);
container.SaveChanges();
Upvotes: 3