/// <summary> /// 在IDBconnection中使用事务 /// </summary> /// <returns></returns> public bool InsertWithTran() { using (var conn = Connection) { int _departmentid = 0, _employeeid = 0, _rnum = 0; var _departmentname = new t_department { departmentname = "应用开发部ENTITY", introduce = "应用开发部主要开始公司的应用平台" }; var _employee = new t_employee { displayname = "Micro", email = "*****@*****.**", loginname = "Micro", password = "******", mobile = "123456789" }; conn.Open(); var _tran = conn.BeginTransaction(); try { _departmentid = conn.Insert(_departmentname, transaction: _tran).Value; ++_rnum; _employeeid = conn.Insert(_employee, transaction: _tran).Value; ++_rnum; conn.Insert(new t_derelation { departmentid = _departmentid, employeeid = _employeeid }, transaction: _tran); ++_rnum; _tran.Commit(); } catch { _rnum = 0; _tran.Rollback(); } return(_rnum > 0); } }
public void entitymapperdemo() { var _employee = new t_employee { displayname = "Micro", email = "*****@*****.**", loginname = "Micro", password = "******", mobile = "123456789", address = "我的地址,不能添加" }; using (var _conn = Connection) { _conn.Open(); _conn.Insert(_employee); } }