Exemplo n.º 1
0
        public virtual T Create(T entity)
        {
            using (connection)
            {
                string query = EntityToSqlUtil.GetInsertQuery(entity);
                entity.Id = connection.QueryFirst <int>(query, entity);
                connection.Close();
            }

            return(entity);
        }
Exemplo n.º 2
0
        public virtual IEnumerable <T> List(BaseFilter filter)
        {
            string          sql = EntityToSqlUtil.GetSelectAllQuery <T>(filter.IncludeBase64Field);
            IEnumerable <T> result;

            using (connection)
            {
                connection.Open();
                result = connection.Query <T>(sql, new { filter });
                connection.Close();
            }
            return(result);
        }
Exemplo n.º 3
0
        public virtual T GetById(int id)
        {
            string query = EntityToSqlUtil.GetSelectByIdQuery <T>();
            T      result;

            using (connection)
            {
                connection.Open();
                result = connection.QueryFirstOrDefault <T>(query, new { Id = id });
                connection.Close();
            }
            return(result);
        }
Exemplo n.º 4
0
        public virtual bool Delete(T entity)
        {
            string query    = EntityToSqlUtil.GetDeleteQuery <T>();
            int    affected = 0;

            using (connection)
            {
                connection.Open();
                affected = connection.Execute(query, entity);
                connection.Close();
            }
            return(affected > 0);
        }