public HowTo_UseTransactions_inDOs() { //<document> string _testid = DateTime.Now.Ticks.ToString(); bool _constraint; long _iduser; long _idgroup; OGen.NTier.UTs.lib.datalayer.DO_User _user = new OGen.NTier.UTs.lib.datalayer.DO_User(); // before beginning a transaction we need to open the connection _user.Connection.Open(); try { // beginning transaction _user.Connection.Transaction.Begin(); // performing some operations on User Data Object _user.Fields.Login = _testid; _user.Fields.Password = _testid; _iduser = _user.insObject(true, out _constraint); // handling constraint code should be added here // commit transaction _user.Connection.Transaction.Commit(); } catch (Exception _ex) { // rollback transaction _user.Connection.Transaction.Rollback(); } finally { // terminate transaction _user.Connection.Transaction.Terminate(); } // closing connection _user.Connection.Close(); _user.Dispose(); _user = null; //</document> }
public HowTo_UseTransactions_betweenDOs_operations() { //<document> string _testid = DateTime.Now.Ticks.ToString(); bool _constraint; long _iduser; long _idgroup; // we need a shared connection between Data Objects OGen.lib.datalayer.DBConnection _con = OGen.NTier.UTs.lib.datalayer.DO__utils.DBConnection_createInstance( OGen.NTier.UTs.lib.datalayer.DO__utils.DBServerType, OGen.NTier.UTs.lib.datalayer.DO__utils.DBConnectionstring, string.Empty ); // before beginning a transaction we need to open the connection _con.Open(); try { // beginning transaction _con.Transaction.Begin(); // sharing connection with User Data Object OGen.NTier.UTs.lib.datalayer.DO_User _user = new OGen.NTier.UTs.lib.datalayer.DO_User(_con); // performing some operations on User Data Object _user.Fields.Login = _testid; _user.Fields.Password = _testid; _iduser = _user.insObject(true, out _constraint); // handling constraint code should be added here _user.Dispose(); _user = null; // sharing connection with Group Data Object OGen.NTier.UTs.lib.datalayer.DO_Group _group = new OGen.NTier.UTs.lib.datalayer.DO_Group(_con); // performing some operations on User Data Object _group.Fields.Name = _testid; _idgroup = _group.insObject(true); _group.Dispose(); _group = null; // sharing connection with Group Data Object OGen.NTier.UTs.lib.datalayer.DO_UserGroup _usergroup = new OGen.NTier.UTs.lib.datalayer.DO_UserGroup(_con); // performing some operations on User Data Object _usergroup.Fields.IDGroup = _idgroup; _usergroup.Fields.IDUser = _iduser; _usergroup.Fields.Relationdate = DateTime.Now; _usergroup.Fields.Defaultrelation = false; _usergroup.setObject(false); _usergroup.Dispose(); _usergroup = null; // commit transaction _con.Transaction.Commit(); } catch (Exception _ex) { // rollback transaction _con.Transaction.Rollback(); } finally { // terminate transaction _con.Transaction.Terminate(); } // closing connection _con.Close(); _con.Dispose(); _con = null; //</document> }