コード例 #1
0
    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);
    }
コード例 #2
0
    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);
    }