/// <summary> /// 开启新的事务,使用本对象调用的所有SQL将在事务内执行 /// </summary> /// <returns></returns> public IDbTransaction StartTransaction() { DataBaseTransaction tra = ContextTransaction; if (tra == null) { tra = new DataBaseTransaction(m_ConnectString, m_DBaseAdapter); ContextTransaction = tra; tra.StartTransaction(IsolationLevel.ReadCommitted); } tra.ReferenceCount++; return(tra); }
/// <summary> /// 回滚事物 /// </summary> public void RollbackTransaction() { DataBaseTransaction tra = ContextTransaction; if (tra != null) { tra.ReferenceCount--; if (tra.ReferenceCount == 0) { tra.Rollback(); tra.Dispose(); ContextTransaction = null; } } }