Exemplo n.º 1
0
        /// <summary>
        /// Converts the <see cref="DbDataReader"/> into an enumerable of <see cref="ExpandoObject"/> objects in an asynchronous way.
        /// </summary>
        /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param>
        /// <param name="tableName">The name of the target table.</param>
        /// <param name="connection">The used <see cref="IDbConnection"/> object.</param>
        /// <param name="transaction">The transaction object that is currently in used.</param>
        /// <returns>An array of <see cref="ExpandoObject"/> objects.</returns>
        internal static async Task <IEnumerable <dynamic> > ToEnumerableAsync(DbDataReader reader,
                                                                              string tableName,
                                                                              IDbConnection connection,
                                                                              IDbTransaction transaction)
        {
            var list = new List <dynamic>();

            if (reader != null && reader.HasRows)
            {
                var func = await FunctionCache.GetDataReaderToExpandoObjectCompileFunctionAsync(reader,
                                                                                                tableName,
                                                                                                connection,
                                                                                                transaction);

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