Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
 public void Delete <T>(T _Object, string whereClause = null, object Params = null, string tableName = null)
 {
     ExecuteQuery(QueryMaker.DeleteQuery(_Object, whereClause), Params);
 }
Exemplo n.º 6
0
 public void Delete <T>(string whereClause, object Params, string tableName = null)
 {
     ExecuteQuery(QueryMaker.DeleteQuery <T>(whereClause), Params);
 }
Exemplo n.º 7
0
 public void Insert <T>(T _Object, string tableName = null)
 {
     ExecuteQuery(QueryMaker.InsertQuery(_Object, tableName));
 }