/// <summary>
        /// Converts the first column of all rows found in <paramref name="reader"/> to an object of type <typeparamref name="TResult"/>
        /// </summary>
        public static async Task <QueryListResult <TResult> > MapToMultipleResultsScalarAsync <TResult>(SqlDataReader reader, CancellationToken cancellationToken)
        {
            var result = new QueryListResult <TResult>();

            while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
            {
                //read the first column of the first row
                var value = reader.GetValue(0);
                //does it have the correct type?
                if (value is TResult)
                {
                    result.Add((TResult)value);
                }
                else
                {
                    result.Add(default(TResult));
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts the first column of all rows found in <paramref name="reader"/> to an object of type <typeparamref name="TResult"/>
        /// </summary>
        /// <param name="reader"></param>
        public static QueryListResult <TResult> MapToMultipleResultsScalar <TResult>(SqlDataReader reader)
        {
            var result = new QueryListResult <TResult>();

            while (reader.Read())
            {
                //read the first column of the first row
                var value = reader.GetValue(0);
                //does it have the correct type?
                if (value is TResult)
                {
                    result.Add((TResult)value);
                }
                else
                {
                    result.Add(default(TResult));
                }
            }

            return(result);
        }
        /// <summary>
        /// Maps all rows found in the first resultset of <paramref name="reader"/> to a collectiobn of objects of type <typeparamref name="T"/> using the provided <paramref name="map"/>.
        /// If <paramref name="reader"/> contains a second resultset, it is expected to contain a scalar value that will be used to set <see cref="PagingData.NumberOfRows"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public static async Task <QueryListResult <T> > MapToMultipleResultsAsync <T>(SqlDataReader reader, DataMap <T> map, CancellationToken cancellationToken) where T : new()
        {
            var result = new QueryListResult <T>();

            //read all rows from the first resultset
            while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
            {
                T instance = new T();
                SetResultValuesToObject(reader, map, instance);
                result.Add(instance);
            }

            return(result);
        }