Exemplo n.º 1
0
        /// <summary>
        /// This must be called after RollbackTransaction or no futher database activity will happen successfully on the current thread.
        /// </summary>
        public static void ThreadTransactionMgrReset()
        {
            TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr();

            try
            {
                if (txMgr.txCount > 0 && txMgr.hasRolledBack == false)
                {
                    txMgr.RollbackTransaction();
                }
            }
            catch {}

            Thread.SetData(txMgrSlot, null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This static method is how you obtain a reference to the TransactionMgr. You cannot call "new" on TransactionMgr.
        /// If a TransactionMgr doesn't exist on the current thread, one is created and returned to you.
        /// </summary>
        /// <returns>The one and only TransactionMgr for this thread.</returns>
        public static TransactionMgr ThreadTransactionMgr()
        {
            TransactionMgr txMgr = null;

            object obj = Thread.GetData(txMgrSlot);

            if (obj != null)
            {
                txMgr = (TransactionMgr)obj;
            }
            else
            {
                txMgr = new TransactionMgr();
                Thread.SetData(txMgrSlot, txMgr);
            }

            return(txMgr);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Execute the Query and loads your BusinessEntity.
        /// You can pass in the conjustion that will be used between the WHERE parameters, either, "AND" or "OR". "AND" is the default.
        /// Also, if you need to be notified that this is being called override BusinessEntity.OnQueryLoad().
        /// </summary>
        /// <returns>True if at least one record was loaded</returns>
        public bool Load(string conjuction)
        {
            bool      loaded = false;
            DataTable dt     = null;

            try
            {
                if ((_aggregateParameters == null || _aggregateParameters.Count <= 0) &&
                    _resultColumns.Length <= 0 && _countAll == false)
                {
                    this._entity._canSave = true;
                }

                this._entity.OnQueryLoad(conjuction);

                IDbCommand cmd = _Load(conjuction);
                _lastQuery = cmd.CommandText;

                IDbDataAdapter da = this._entity.CreateIDbDataAdapter();
                da.SelectCommand = cmd;

                TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr();

                dt = new DataTable(_entity.MappingName);

                txMgr.Enlist(cmd, _entity);
                DbDataAdapter dbDataAdapter = this._entity.ConvertIDbDataAdapter(da);
                dbDataAdapter.Fill(dt);
                txMgr.DeEnlist(cmd, _entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                this._entity.DataTable = dt;
                loaded = (dt.Rows.Count > 0);
            }

            return(loaded);
        }