Exemplo n.º 1
0
        /// <summary>
        /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity objects in an asynchronous way.
        /// </summary>
        /// <typeparam name="TEntity">The data entity type to convert.</typeparam>
        /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param>
        /// <param name="connection">The used <see cref="IDbConnection"/> object.</param>
        /// <param name="connectionString">The raw connection string.</param>
        /// <param name="transaction">The transaction object that is currently in used.</param>
        /// <param name="enableValidation">Enables the validation after retrieving the database fields.</param>
        /// <returns>An array of data entity objects.</returns>
        internal static async Task <IEnumerable <TEntity> > ToEnumerableInternalAsync <TEntity>(DbDataReader reader,
                                                                                                IDbConnection connection   = null,
                                                                                                string connectionString    = null,
                                                                                                IDbTransaction transaction = null,
                                                                                                bool enableValidation      = true)
            where TEntity : class
        {
            var list = new List <TEntity>();

            if (reader != null && reader.IsClosed == false && reader.HasRows)
            {
                var func = await FunctionCache.GetDataReaderToDataEntityCompiledFunctionAsync <TEntity>(reader,
                                                                                                        connection,
                                                                                                        connectionString,
                                                                                                        transaction,
                                                                                                        enableValidation);

                while (await reader.ReadAsync())
                {
                    list.Add(func(reader));
                }
            }
            return(list);
        }