Пример #1
0
        /// <summary>
        /// Map to an existing instance
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection"></param>
        /// <param name="query"></param>
        /// <param name="ignoreExtraRows"></param>
        /// <param name="target"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        protected bool TryGetSingle <T>(
            object query,
            T target,
            bool ignoreExtraRows,
            params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Select, query, Transaction, parameters);

            wrapper.ExpectSelectQuery();

            bool looped = false;

            using (IDataReader reader = wrapper.RunQuery(StorageController))
            {
                DataReaderWrapper drWrap  = new DataReaderWrapper(reader);
                MapperWrapper <T> mapWrap = new MapperWrapper <T>(drWrap);

                foreach (var item in mapWrap)
                {
                    if (looped)
                    {
                        throw new IQException("More than one record was returned by the Single<T> query");
                    }
                    target = item;
                    looped = true;
                    if (ignoreExtraRows)
                    {
                        break;
                    }
                }
            }
            return(looped);
        }
Пример #2
0
        /// <summary>
        /// Return true of anything matches the criteria
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="where"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        //public bool Any<T>(string where, params object[] parameters)
        //{
        //    var wrapper = new SqlQueryParser<T>(QueryType.Where, where, Transaction, parameters);
        //    wrapper.ExpectSelectQuery();
        //    //wrapper.QueryFull.Top = 1;
        //    wrapper.QueryFull.Select = "1";
        //    int target;
        //    return TryGetSingle<int>(wrapper,false,out target);

        //}
        public IEnumerable <T> Where <T>(string where, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Where, where, Transaction, parameters);

            return(MapAll <T>(wrapper.RunQuery(StorageController), wrapper.Buffered));
        }
Пример #3
0
        public IDataReader Query(string query, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <object>(0, query, Transaction, parameters);

            return(wrapper.RunQuery(StorageController));
        }
Пример #4
0
        public IEnumerable <T> Select <T>(object query, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Select, query, Transaction, parameters);

            return(MapAll <T>(wrapper.RunQuery(StorageController), wrapper.Buffered));
        }