Example #1
0
        public T GetById(int id)
        {
            Thread.Sleep(shortSleep);
            T result;

            using (SqlConnection connection = new SqlConnection(SQLCommon <T> .GetConnectionString()))
            {
                string        query  = string.Format("select * from {0} where {1}={2}", tableName, keyName, id);
                SqlDataReader reader = SQLCommon <T> .ExecuteReader(query, null, connection);

                reader.Read();
                result = SQLCommon <T> .ConvertRowToEntity(reader);
            }

            return(result);
        }
Example #2
0
        public List <T> GetAll()
        {
            Thread.Sleep(longSleep);
            List <T> result = new List <T>();

            using (SqlConnection connection = new SqlConnection(SQLCommon <T> .GetConnectionString()))
            {
                string        query  = string.Format("select * from {0}", tableName);
                SqlDataReader reader = SQLCommon <T> .ExecuteReader(query, null, connection);

                while (reader.Read())
                {
                    result.Add(SQLCommon <T> .ConvertRowToEntity(reader));
                }
            }

            return(result);
        }
Example #3
0
        public List <T> GetByTemplate(T template, bool and = false)
        {
            Thread.Sleep(shortSleep);
            List <T>            result       = new List <T>();
            List <string>       whereClauses = new List <string>();
            List <SqlParameter> sqlParams    = new List <SqlParameter>();

            using (SqlConnection connection = new SqlConnection(SQLCommon <T> .GetConnectionString()))
            {
                string query = string.Format("select * from {0}", tableName);
                query += SQLCommon <T> .CreateWhereClause(template, and, sqlParams);

                SqlDataReader reader = SQLCommon <T> .ExecuteReader(query, sqlParams, connection);

                while (reader.Read())
                {
                    result.Add(SQLCommon <T> .ConvertRowToEntity(reader));
                }
            }

            return(result);
        }