Using (VAR srop = dbhelper. currentdb. gettransaction () {id = bp. addmodel (model ). tostr (); # region participate in the real estate information if (ID. toint32 ()> 0) {fy_activityprojectserver dtlserver = new fy_activityprojectserver (); For (INT I = 0; I <= This. projects. items. count; I ++) {If (this. projects. items [I]. selected) {fy_activityproject DTL = new fy_activityproject (); DTL. activityid = ID. toint32 (); DTL. projectid = This. projects. items [I]. value. toint32 (); DTL. isdel = false; dtllist. add (DTL) ;}} dtlserver. addmodel (dtllist) ;}# endregion srop. complete ();}
The above is the first method.
The second method is as follows:
Dbhelper. currentdb. begintransaction (); // The transaction starts this. modeldatacollect (); fy_activityserver BP = new fy_activityserver (); try {id = bp. addmodel (model ). tostr (); # region participate in the real estate information if (ID. toint32 ()> 0) {fy_activityprojectserver dtlserver = new fy_activityprojectserver (); For (INT I = 0; I <= This. projects. items. count; I ++) {If (this. projects. items [I]. selected) {fy_activityproject DTL = new fy_activityproject (); DTL. activityid = ID. toint32 (); DTL. projectid = This. projects. items [I]. value. toint32 (); DTL. isdel = false; dtllist. add (DTL) ;}} dtlserver. addmodel (dtllist) ;}# endregion dbhelper. currentdb. completetransaction ();} catch (exception) {dbhelper. currentdb. aborttransaction ();}
The preceding operations have two insert operations.
The first insert can be successfully inserted, and the second insert method intentionally reports an error,
The problem arises,
Petapoco does not roll back, causing the first operation to be successfully inserted and the second operation to be inserted to fail.
Solutions
Why can't petapoco4.0 transactions be rolled back?