Dashboard > WebObjects > Home > Programming__WebObjects-EOF-Using EOF-Deleting
  WebObjects Log In View a printable version of the current page.  
  Programming__WebObjects-EOF-Using EOF-Deleting
Added by David LeBer, last edited by Helmut Schottmüller on Mar 27, 2008  (view change) show comment
Labels: 
(None)

Deleting in EOF

Usually deleting is pretty easy:

Person person; //Assume is an EO that exists
EOEditingContext ec = person.editingContext(); //Always make sure you are using the correct editing context
ec.deleteObject(person); //Mark the EO for deletion
ec.saveChanges(); //Commit

A little more robust example:

Person person; /Assume is an EO that exists
EOEditingContext ec = person.editingContext();
ec.deleteObject(person);

try {
  ec.saveChanges();
} catch (Exception e) {
  //something bad happened, the delete didn't occur
  //well don't just stand there, do something about it!
  ec.revert(); // clean up the mess
}

NOTE: These examples assume that correct EOEditingContext locking is occuring, ProjectWonder's ERXEC auto-locking is highly recommended.

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators