/// <summary> /// Execute the query and return an array of new instances of typed results filled with data table result. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="converter"></param> /// <returns>Array of typed results</returns> public async virtual Task <IEnumerable <T> > ExecuteTableAsync <T>(Func <Schema.DataRow, Task <T> > converter) { var table = await ExecuteInternalCommand(async() => { using (DbDataReader dr = await this.Command.ExecuteReaderAsync()) { return(await DataReaderConvertor.ToDataTableAsync(dr)); } }); if (table != null && table.Rows != null) { return(table.Rows.Select(async row => await converter.Invoke(row)).Select(i => i.GetAwaiter().GetResult())); } else { return new T[] { } }; }
/// <summary> /// Execute the query and fill the specified T object with the first row of results /// </summary> /// <typeparam name="T">Object type</typeparam> /// <param name="converter"></param> /// <returns>First row of results</returns> public async virtual Task <T> ExecuteRowAsync <T>(Func <Schema.DataRow, Task <T> > converter) { if (TypeExtension.IsPrimitive(typeof(T))) { return(await this.ExecuteScalarAsync <T>()); } else { // Get DataRow var table = await ExecuteInternalCommand(async() => { using (DbDataReader dr = await this.Command.ExecuteReaderAsync(System.Data.CommandBehavior.SingleRow)) { return(await DataReaderConvertor.ToDataTableAsync(dr)); } }); var row = table?.Rows?.FirstOrDefault(); // Return return(row != null ? await converter.Invoke(row) : default(T)); } }