Ejemplo 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);
        }
Ejemplo n.º 2
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);
        }