public IEnumerable <EntityORM> Read(string table, HashSet <string> attributes, DbTools.WhereRequest[] whereRequests = null) { List <EntityORM> entities = new List <EntityORM>(); try { string sqlExpression = DbTools.CreateQuery(table, attributes, whereRequests); dbConnect.OpenConnection(); OracleCommand command = new OracleCommand(sqlExpression, dbConnect.GetConnection()); OracleDataReader reader = command.ExecuteReader(); while (reader.Read()) { EntityORM entity = new EntityORM(); foreach (string attribute in attributes) { entity.attributeValue.Add(DbTools.GetVariableAttribute(attribute), reader[attribute]); } entities.Add(entity); } } catch (DbException ex) { logger.Info("Exception.Message: {0}", ex.Message); } finally { dbConnect.CloseConnection(); } return(entities); }
public EntityORM Read(object attribute_value, string attribute_name, HashSet <string> attributes, string table) { EntityORM entity = null; try { string sqlExpression = $"SELECT * FROM {table} WHERE {attribute_name} = {attribute_value}"; dbConnect.OpenConnection(); OracleCommand command = new OracleCommand(sqlExpression, dbConnect.GetConnection()); OracleDataReader reader = command.ExecuteReader(); reader.Read(); if (reader.HasRows) { entity = new EntityORM(); foreach (string attribute in attributes) { object value = reader[attribute]; entity.attributeValue.Add(attribute, value); } } reader.Close(); } catch (DbException ex) { logger.Info("Exception.Message: {0}", ex.Message); } finally { dbConnect.CloseConnection(); } return(entity); }