/// <summary> /// Execute the query and return an array of new instances of typed results filled with data table result. /// </summary> /// <typeparam name="T">Object type</typeparam> /// <returns>Array of typed results</returns> /// <example> /// <code> /// Employee[] emp = cmd.ExecuteTable<Employee>(); /// var x = cmd.ExecuteTable<Employee>(); /// </code> /// <remarks> /// Result object property (ex. Employee.Name) may be tagged with the ColumnAttribute /// to set which column name (ex. [Column("Name")] must be associated to this property. /// </remarks> /// </example> public async virtual Task <IEnumerable <T> > ExecuteTableAsync <T>() { return(await ExecuteInternalCommand(async() => { using (DbDataReader dr = await this.Command.ExecuteReaderAsync()) { // Primitive type: Executable<string>() if (TypeExtension.IsPrimitive(typeof(T))) { return await DataReaderConvertor.ToPrimitivesAsync <T>(dr); } // Dynamic type: Executable<dynamic>() else if (DynamicConvertor.IsDynamic(typeof(T))) { return await DataReaderConvertor.ToDynamicAsync <T>(dr); } // Object type: Executable<Employee>() else { return (await DataReaderConvertor.ToTypeAsync <T>(dr)).Rows; } } })); }
/// <summary> /// Execute the query and return an array of new instances of typed results filled with data table result. /// </summary> /// <typeparam name="T">Object type</typeparam> /// <param name="itemOftype"></param> /// <returns>Array of typed results</returns> /// <example> /// <code> /// Employee emp = new Employee(); /// var x = cmd.ExecuteTable(new { emp.Age, emp.Name }); /// var y = cmd.ExecuteTable(new { Age = 0, Name = "" }); /// </code> /// <remarks> /// Result object property (ex. Employee.Name) may be tagged with the ColumnAttribute /// to set which column name (ex. [Column("Name")] must be associated to this property. /// </remarks> /// </example> public async virtual Task <IEnumerable <T> > ExecuteTableAsync <T>(T itemOftype) { return(await ExecuteInternalCommand(async() => { using (DbDataReader dr = await this.Command.ExecuteReaderAsync()) { if (TypeExtension.IsPrimitive(typeof(T))) { return await DataReaderConvertor.ToPrimitivesAsync <T>(dr); } else { return await DataReaderConvertor.ToAnonymousAsync <T>(dr); } } })); }