public static async Task <List <T> > QueryAsync <T>(this Database db, DbCommand command) where T : class, new() { List <T> result = new List <T>(); await db.ExecuteReaderAsync(command, (reader) => { DataReaderPropertySetters <T> setters = new DataReaderPropertySetters <T>(reader); while (reader.Read()) { result.Add(reader.MapToObject(setters)); } }); return(result); }
public static T MapToObject <T>(this DbDataReader reader, DataReaderPropertySetters <T> setters) where T : new() { T result = new T(); foreach (PropertySetter <T> setter in setters.SetterFunctions) { try { setter.setterFunc(result, reader); } catch (Exception ex) { throw new Exception("Error setting property for " + setter.columnName, ex); } } return(result); }