コード例 #1
0
ファイル: DynamicQuery.cs プロジェクト: Farschidus/Ciemesus
        /// <summary>
        /// Execute the Query and loads your CoreEntity.
        /// 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 CoreEntity.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);
        }