Пример #1
0
        /// <summary>
        /// Updates an entity in the database.
        /// </summary>
        /// <param name="entity">The entity to be updated</param>
        /// <returns>The number of updated records</returns>
        public int Update(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentException("Entity must not be null.");
            }

            var properties = BuildPropertyList(UpdateFields);
            var parameters = BuildParameterList(UpdateFields, entity);

            parameters.Add(Key.Property, (TKey)Key.Getter(entity));

            var result = 0;

            if (properties.Count <= 0)
            {
                return(result);
            }

            var connection = GetConnection();

            try {
                var keyParamName = _queryGenerator.FormatSqlParameter(Key.Property);
                result = connection.Execute(_queryGenerator.Update(Table, properties, Key, keyParamName), parameters);
            }
            finally {
                if (!_useProvidedConnection)
                {
                    connection.Dispose();
                }
            }

            return(result);
        }
Пример #2
0
 public virtual void Edit(T entity)
 {
     ExecuteQuery(_queryGenerator.Update(entity));
 }