Exemple #1
0
        /// <summary>
        /// 执行查询文本并将结果以一个 <see cref="IEnumerable{T}"/> 的序列返回。
        /// </summary>
        /// <typeparam name="T">查询对象类型。</typeparam>
        /// <param name="queryCommand">查询命令。</param>
        /// <param name="segment">数据分段对象。</param>
        /// <param name="parameters">查询参数集合。</param>
        /// <param name="rowMapper">数据行映射器。</param>
        /// <returns>一个 <typeparamref name="T"/> 类型的对象的枚举器。</returns>
        public virtual IEnumerable <T> ExecuteEnumerable <T>(IQueryCommand queryCommand, IDataSegment segment = null, ParameterCollection parameters = null, IDataRowMapper <T> rowMapper = null)
        {
            Guard.ArgumentNull(queryCommand, nameof(queryCommand));

            rowMapper ??= RowMapperFactory.CreateRowMapper <T>();
            rowMapper.RecordWrapper = Provider.GetService <IRecordWrapper>();
            using var reader        = ExecuteReader(queryCommand, segment, parameters, CommandBehavior.Default);
            while (reader.Read())
            {
                yield return(rowMapper.Map(this, reader));
            }
        }
        public static IEnumerable <MappedRow <T> > MappedRowsUsing <T>(this IEnumerable <DataRow> rows,
                                                                       IDataRowMapper <T> mapper) where T : class
        {
            var result = new List <MappedRow <T> >();

            foreach (var row in rows)
            {
                result.Add(mapper.Map(row));
            }

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// 执行查询文本并将结果以一个 <see cref="IEnumerable&lt;T&gt;"/> 的序列返回。
        /// </summary>
        /// <typeparam name="T">查询对象类型。</typeparam>
        /// <param name="queryCommand">查询命令。</param>
        /// <param name="segment">数据分段对象。</param>
        /// <param name="parameters">查询参数集合。</param>
        /// <param name="rowMapper">数据行映射器。</param>
        /// <returns>一个 <typeparamref name="T"/> 类型的对象的枚举器。</returns>
        public virtual IEnumerable <T> ExecuteEnumerable <T>(IQueryCommand queryCommand, IDataSegment segment = null, ParameterCollection parameters = null, IDataRowMapper <T> rowMapper = null)
        {
            Guard.ArgumentNull(queryCommand, "queryCommand");

            rowMapper = rowMapper ?? RowMapperFactory.CreateRowMapper <T>();
            rowMapper.RecordWrapper = Provider.GetService <IRecordWrapper>();
            using (var reader = ExecuteReader(queryCommand, segment, parameters))
            {
                while (reader.Read())
                {
                    yield return(rowMapper.Map(reader));
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 异步的,执行查询文本并将结果以一个 <see cref="IEnumerable{T}"/> 的序列返回。
        /// </summary>
        /// <typeparam name="T">查询对象类型。</typeparam>
        /// <param name="queryCommand">查询命令。</param>
        /// <param name="segment">数据分段对象。</param>
        /// <param name="parameters">查询参数集合。</param>
        /// <param name="rowMapper">数据行映射器。</param>
        /// <param name="cancellationToken">取消操作的通知。</param>
        /// <returns>一个 <typeparamref name="T"/> 类型的对象的枚举器。</returns>
        public async virtual IAsyncEnumerable <T> ExecuteEnumerableAsync <T>(IQueryCommand queryCommand, IDataSegment segment = null, ParameterCollection parameters = null, IDataRowMapper <T> rowMapper = null, CancellationToken cancellationToken = default)
        {
            Guard.ArgumentNull(queryCommand, nameof(queryCommand));

            rowMapper = rowMapper ?? RowMapperFactory.CreateRowMapper <T>();
            rowMapper.RecordWrapper = Provider.GetService <IRecordWrapper>();
            using (var reader = (DbDataReader)(await ExecuteReaderAsync(queryCommand, segment, parameters, cancellationToken)))
            {
                while (await reader.ReadAsync(cancellationToken))
                {
                    yield return(rowMapper.Map(this, reader));
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// 异步的,执行查询文本并将结果以一个 <see cref="IEnumerable{T}"/> 的序列返回。
        /// </summary>
        /// <typeparam name="T">查询对象类型。</typeparam>
        /// <param name="queryCommand">查询命令。</param>
        /// <param name="segment">数据分段对象。</param>
        /// <param name="parameters">查询参数集合。</param>
        /// <param name="rowMapper">数据行映射器。</param>
        /// <param name="cancellationToken">取消操作的通知。</param>
        /// <returns>一个 <typeparamref name="T"/> 类型的对象的枚举器。</returns>
        public async virtual IAsyncEnumerable <T> ExecuteAsyncEnumerable <T>(IQueryCommand queryCommand, IDataSegment segment = null, ParameterCollection parameters = null, IDataRowMapper <T> rowMapper = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            Guard.ArgumentNull(queryCommand, nameof(queryCommand));

            rowMapper ??= RowMapperFactory.CreateRowMapper <T>();
            rowMapper.RecordWrapper = Provider.GetService <IRecordWrapper>();
            using var reader        = (InternalDataReader) await ExecuteReaderAsync(queryCommand, segment, parameters, CommandBehavior.Default, cancellationToken);

            while (await reader.ReadAsync(cancellationToken))
            {
                yield return(rowMapper.Map(this, reader));
            }
        }
        public OrderProcess Get(Guid id)
        {
            var orderProcessRow = _databaseGateway.GetSingleRowUsing(_queryFactory.Get(id));

            if (orderProcessRow == null)
            {
                return(null);
            }

            var orderProcess = _orderProcessMapper.Map(orderProcessRow).Result;

            foreach (var row in _databaseGateway.GetRowsUsing(_queryFactory.GetItems(id)))
            {
                orderProcess.AddItem(_orderProcessItemMapper.Map(row).Result);
            }

            foreach (var row in _databaseGateway.GetRowsUsing(_queryFactory.GetStatuses(id)))
            {
                orderProcess.AddStatus(_orderProcessStatusMapper.Map(row).Result);
            }

            return(orderProcess);
        }
        public T FetchItemUsing(IQuery query)
        {
            var row = _databaseGateway.GetSingleRowUsing(query);

            return(row == null ? default(T) : _dataRowMapper.Map(row).Result);
        }