コード例 #1
0
 /// <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);
     }
 }
コード例 #2
0
 /// <summary>
 /// 实体插入数据
 /// </summary>
 public int?InsertWithEntity()
 {
     using (var conn = Connection)
     {
         var _entity = new t_department {
             departmentname = "应用开发部ENTITY", introduce = "应用开发部主要开始公司的应用平台"
         };
         conn.Open();
         return(conn.Insert(_entity));
     }
 }