Wiki source code of EOF-Using EOF-Deleting

Last modified by Pascal Robert on 2010/09/11 23:51

Hide last authors
David LeBer 1.1 1 == Deleting in EOF ==
2
3 Usually deleting is pretty easy:
4
Pascal Robert 5.1 5 {{code 0="java"}}
David LeBer 1.1 6
7 Person person; //Assume is an EO that exists
8 EOEditingContext ec = person.editingContext(); //Always make sure you are using the correct editing context
9 ec.deleteObject(person); //Mark the EO for deletion
10 ec.saveChanges(); //Commit
11
12 {{/code}}
13
14 A little more robust example:
15
Pascal Robert 5.1 16 {{code 0="java"}}
David LeBer 1.1 17
18 Person person; /Assume is an EO that exists
19 EOEditingContext ec = person.editingContext();
20 ec.deleteObject(person);
21
22 try {
23 ec.saveChanges();
24 } catch (Exception e) {
25 //something bad happened, the delete didn't occur
26 //well don't just stand there, do something about it!
hschottm 3.1 27 ec.revert(); // clean up the mess
David LeBer 1.1 28 }
29
30 {{/code}}
31
32 //NOTE: These examples assume that correct EOEditingContext locking is occuring, ProjectWonder's ERXEC auto-locking is highly recommended.//