Пример #1
0
        // TODO: return IEnumerable so we don't have to .ToList()
        IList <T> ExecuteQuery(string sql, object param)
        {
            try
            {
                IEnumerable <T> result = _map(_getConnection(), _getTransaction != null ? _getTransaction() : null, sql, param);

                if (_hasOverallCount)
                {
                    IHasOverallCount overallCount = result as IHasOverallCount;

                    if (overallCount != null)
                    {
                        _overallCount = overallCount.OverallCount;
                    }
                }

                IList <T> results = result.ToList();

                if (_massage != null)
                {
                    _massage(_getConnection(), _getTransaction != null ? _getTransaction() : null, results);
                }

                return(results);
            }
            catch (Exception ex)
            {
                throw new DapperGriddlyException("Error executing list query.", sql, param, ex);
            }
        }
Пример #2
0
        protected IEnumerable <T> DefaultMap(IDbConnection cn, IDbTransaction tx, string sql, object param)
        {
            IEnumerable <T> result = cn.Query <T>(sql, param, tx);

            if (_hasOverallCount)
            {
                IHasOverallCount firstRow = result.FirstOrDefault() as IHasOverallCount;
                ListPage <T>     lp       = new ListPage <T>();

                if (firstRow != null)
                {
                    lp.OverallCount = firstRow.OverallCount;
                    lp.AddRange(result);
                }

                result = lp;
            }

            return(result);
        }