Exemple #1
0
        // GetList
        public override async Task <List <T> > GetListAsync <T>(IDbCommand command)
        {
            List <T> modelObjList = new List <T>();

            try
            {
                if (command.Connection.State != ConnectionState.Open)
                {
                    OpenConnection(command.Connection);
                }

                var cmd    = command as SqlCommand;
                var reader = await cmd.ExecuteReaderAsync();

                if (reader.HasRows)
                {
                    IDataTransferObject <T> mapper = DataMapperFactory.GetMapper <T>();
                    modelObjList = mapper.GetList(reader).ToList <T>();
                    reader.Close();
                }
                // We return either the populated list if there was data,
                // or if there was no data we return an empty list.
                return(modelObjList);
            }
            catch (DatabaseException dbExp)
            {
                throw dbExp;
            }
            catch (SqlException sqlExp)
            {
                throw new DatabaseException(DatabaseException.ErrorCode.EXECUTE_ERROR, "Error executing query", sqlExp);
            }
            catch (Exception e)
            {
                throw new DatabaseException(DatabaseException.ErrorCode.UNKNOWN, "Error executing query", e);
            }
            finally
            {
                CloseConnection(command.Connection);
            }
        }