Exemplo n.º 1
0
        public PagedList <T> ReadPageList <T>()
        {
            Type          targetType = typeof(T);
            PagedList <T> result     = new PagedList <T>();
            var           func       = RepositoryHelper.GetReader(this.hashKey, targetType, this.reader, this.isMappingIgnoreCase);

            while (reader.Read())
            {
                var objResult = func?.Invoke(reader);
                if (objResult == null)
                {
                    continue;
                }
                if (objResult is T)
                {
                    result.Add((T)objResult);
                }
                else
                {
                    result.Add((T)Convert.ChangeType(objResult, targetType, CultureInfo.InvariantCulture));
                }
            }
            this.ReadNextResult();
            return(result);
        }
Exemplo n.º 2
0
        public PagedList <T> ReadPageList <T>(int pageIndex, int pageSize, int recordsTotal)
        {
            Type          targetType = typeof(T);
            PagedList <T> result     = new PagedList <T>();

            result.Data = new List <T>();
            var func = RepositoryHelper.GetReader(this.hashKey, targetType, this.reader, this.isMappingIgnoreCase);

            while (reader.Read())
            {
                var objResult = func?.Invoke(reader);
                if (objResult == null)
                {
                    continue;
                }
                if (objResult is T)
                {
                    result.Data.Add((T)objResult);
                }
                else
                {
                    result.Data.Add((T)Convert.ChangeType(objResult, targetType, CultureInfo.InvariantCulture));
                }
            }
            this.ReadNextResult();
            result.PageIndex    = pageIndex;
            result.PageSize     = pageSize;
            result.RecordsTotal = recordsTotal;
            if (pageSize <= 0)
            {
                throw new ArgumentException("pageSize不能<=0");
            }
            result.PageTotal = (int)Math.Ceiling((double)recordsTotal / pageSize);
            return(result);
        }
Exemplo n.º 3
0
        private async Task QueryImplInternalAsync <TTarget>(int hashKey, Type targetType, string sql, DbConnection conn, DbTransaction trans, CommandType cmdType, CommandBehavior behavior, Action <object> resultHandler, object objParameter, Type paramType)
        {
            DbCommand command = conn.CreateCommand();

            command.CommandText = sql;
            command.CommandType = cmdType;
            command.Transaction = trans;
            if (objParameter != null)
            {
                var paramAction = RepositoryHelper.GetActionCache(hashKey, sql, paramType, this.Provider);
                paramAction(command, objParameter);
            }
            this.Open(conn);
            DbDataReader reader = await command.ExecuteReaderAsync(behavior);

            var func = RepositoryHelper.GetReader(hashKey, targetType, reader, this.Provider.IsMappingIgnoreCase);

            while (reader.Read())
            {
                resultHandler(func?.Invoke(reader));
            }
            while (reader.NextResult())
            {
            }
#if COREFX
            try { command.Cancel(); } catch { }
#else
            reader.Close();
#endif
            reader.Dispose();
            reader = null;
        }
Exemplo n.º 4
0
        public T Read <T>()
        {
            Type targetType = typeof(T);
            T    result     = default(T);
            var  func       = RepositoryHelper.GetReader(this.hashKey, targetType, this.reader, this.isMappingIgnoreCase);

            while (reader.Read())
            {
                var objResult = func?.Invoke(reader);
                if (objResult == null || objResult is T)
                {
                    result = (T)objResult;
                }
                else
                {
                    result = (T)Convert.ChangeType(objResult, targetType, CultureInfo.InvariantCulture);
                }
            }
            this.ReadNextResult();
            return(result);
        }