public List <T> GetAll <T>(string query = null, string whereClause = null, object Params = null) { var results = new List <T>(); var properties = GetReadableProperties <T>(); query = QueryMaker.SelectQuery <T>(query, whereClause); using (SqlConnection Connection = new SqlConnection(ConnectionString)) { Connection.Open(); SqlCommand cmd = GetSqlCommandWithParams(query, Connection, Params); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var item = Activator.CreateInstance <T>(); foreach (var property in properties) { DBReader(item, property, reader); } results.Add(item); } } Connection.Close(); return(results); } }
public T Get <T>(string query = null, string whereClause = null, object Params = null) { T t = Activator.CreateInstance <T>(); try { List <PropertyInfo> properties = GetReadableProperties <T>(); query = QueryMaker.SelectQuery <T>(query, whereClause); using (SqlConnection Connection = new SqlConnection(ConnectionString)) { Connection.Open(); SqlCommand cmd = GetSqlCommandWithParams(query, Connection, Params); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { foreach (var property in properties) { DBReader(t, property, reader); } } } Connection.Close(); } return(t); } catch (SqlException ex) { return(t); } }