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); } }
public void InsertAndGetID <T>(T _Object, string schemaName = null, string tableName = null) { string query = QueryMaker.InsertQuery(_Object, tableName) + "SELECT SCOPE_IDENTITY();"; int ID = GetScaler(query); var PrimaryKey = GetKeyProperty <T>(); PrimaryKey.SetValue(_Object, ID); }
public PageListObject <T> GetPagedList <T>(string query, Dictionary <string, string> sortAndOrder, int numberOfRecords, int pageNumber, object Params) { int offset = numberOfRecords * pageNumber; var Querries = QueryMaker.GetPagerQueries <T>(query, sortAndOrder, offset, numberOfRecords); string mainquery = Querries.Query; string countquery = Querries.CountQuery; return(PagedResults <T>(numberOfRecords, pageNumber, Params, offset, mainquery, countquery)); }
public void Delete <T>(T _Object, string whereClause = null, object Params = null, string tableName = null) { ExecuteQuery(QueryMaker.DeleteQuery(_Object, whereClause), Params); }
public void Delete <T>(string whereClause, object Params, string tableName = null) { ExecuteQuery(QueryMaker.DeleteQuery <T>(whereClause), Params); }
public void Insert <T>(T _Object, string tableName = null) { ExecuteQuery(QueryMaker.InsertQuery(_Object, tableName)); }