Exemple #1
0
        public IList <TOutput> QueryMany()
        {
            if (_mapper == null)
            {
                throw new ArgumentException("No IMapper defined");
            }

            if (_useCache)
            {
                IList <TOutput> output = _cacheRepository.GetEntry <IList <TOutput> >(GetCacheKey());
                if (output != null)
                {
                    return(output);
                }
            }

            OpenConnection();
            try
            {
                OnQueryExecutingHandler(new QueryExecutionEventArgs {
                    Query = this
                });
                IDataReader reader = Command.ExecuteReader();
                OnQueryExecutedHandler(new QueryExecutionEventArgs {
                    Query = this
                });
                OnMappingExecutingHandler();
                IList <TOutput> output = _mapper.MapToList(new SqlDataReader(reader));
                OnMappingExecutedHandler();

                if (_useCache)
                {
                    _cacheRepository.Insert(GetCacheKey(), output, _cacheDuration ?? TimeSpan.FromHours(1));
                }

                return(output);
            }
            catch (Exception e)
            {
                OnErrorHandler(new QueryErrorEventArgs {
                    Exception = e
                });
                if (CatchExceptions)
                {
                    return(default(IList <TOutput>));
                }
                throw;
            }
            finally
            {
                CloseConnection();
            }
        }