Exemplo n.º 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, parameters);

            wrapper.ExpectSelectQuery();

            bool looped = false;

            using (IDataReader reader = wrapper.RunQuery(StorageController))
            {
                while (reader.Read())
                {
                    if (looped)
                    {
                        throw new IQException("More than one record was returned by the Single<T> query");
                    }
                    reader.Map(target);
                    looped = true;
                    if (ignoreExtraRows)
                    {
                        break;
                    }
                }
            }
            return(looped);
        }
Exemplo n.º 2
0
        protected bool TryGetSingle <T>(
            object query,
            out T target,
            bool ignoreExtraRows,
            params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters);

            wrapper.ExpectSelectQuery();

            T    output = default(T);
            bool looped = false;

            using (IDataReader reader = wrapper.RunQuery(StorageController))
            {
                while (reader.Read())
                {
                    if (looped)
                    {
                        throw new IQException("More than one record was returned by the Single<T> query");
                    }
                    output = reader.Map <T>();
                    looped = true;
                    if (ignoreExtraRows)
                    {
                        break;
                    }
                }
            }
            if (!looped)
            {
                target = (T)Utils.DefaultValue(typeof(T));
                return(false);
            }
            else
            {
                target = output;
                return(true);
            }
        }
Exemplo n.º 3
0
        public IDataReader Query(string query, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <object>(0, query, parameters);

            return(wrapper.RunQuery(StorageController));
        }
Exemplo n.º 4
0
        public IEnumerable <T> Select <T>(object query, params object[] parameters)
        {
            var wrapper = new SqlQueryParser <T>(QueryType.Select, query, parameters);

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