Execute() public method

public Execute ( ) : void
return void
コード例 #1
0
        public void Update(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            Type objectType = obj.GetType();
            TableConfiguration  tableConfiguration = getTableConfiguration(objectType);
            PropertyMap         keyPropertyMap     = getKeyPropertyMap(tableConfiguration);
            IList <PropertyMap> propertyMaps       = tableConfiguration.PropertyMaps.Where(x => x.KeyType == KeyType.None).ToList();

            string[] setClauses = propertyMaps.Select(x => string.Format("{0} = {1}", x.ColumnName, x.ParameterName)).ToArray();

            //TODO: How to handle different database dialects?
            string commandText = string.Format("UPDATE {0} SET {1} WHERE {2} = {3}", tableConfiguration.TableMap.TableName, string.Join(", ", setClauses), keyPropertyMap.ColumnName, keyPropertyMap.ParameterName);

            NonQueryCommand nonQueryCommand = new NonQueryCommand(_connection, _transaction, commandText);

            foreach (PropertyMap propertyMap in tableConfiguration.PropertyMaps)
            {
                object parameterValue = getPropertyValue(obj, propertyMap.PropertyName);
                nonQueryCommand.addParameter(propertyMap.ParameterName, parameterValue, propertyMap.ParameterType);
            }

            nonQueryCommand.Execute();
        }
コード例 #2
0
        public void Delete(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            Type objectType = obj.GetType();
            TableConfiguration tableConfiguration = getTableConfiguration(objectType);
            PropertyMap        keyPropertyMap     = getKeyPropertyMap(tableConfiguration);

            string commandText = string.Format("DELETE FROM {0} WHERE {1} = {2}", tableConfiguration.TableMap.TableName, keyPropertyMap.ColumnName, keyPropertyMap.ParameterName);

            NonQueryCommand nonQueryCommand = new NonQueryCommand(_connection, _transaction, commandText);

            object parameterValue = getPropertyValue(obj, keyPropertyMap.PropertyName);

            nonQueryCommand.addParameter(keyPropertyMap.ParameterName, parameterValue, keyPropertyMap.ParameterType);

            nonQueryCommand.Execute();
        }