Пример #1
0
 private void AddParametersToCommand(DbCommand cmd, IEnumerable <ColumnInfo> columns)
 {
     foreach (ColumnInfo colInfo in columns)
     {
         var par = cmd.CreateParameter();
         par.ParameterName = $"@{colInfo.Name}";
         _provider.SetParameterDbType(par, _tableInfo.Name, colInfo.Name);
         cmd.Parameters.Add(par);
     }
 }
Пример #2
0
        /// <summary>
        /// Fills command's parameters with values from <paramref name="item" />.
        /// </summary>
        /// <param name="command">Command which parameters are filled.</param>
        /// <param name="item">Item, from which command is filled.</param>
        /// <exception cref="System.ArgumentNullException">Either <paramref name="command" /> or <paramref name="item" />
        /// is <c>null</c>.</exception>
        public void FillCommand(DbCommand command, T item)
        {
            Check.NotNull(command, nameof(command));
            Check.NotNull(item, nameof(item));

            foreach (ColumnInfo colInfo in this.GetQueryColumns())
            {
                string paramName = $"@{colInfo.Name}";
                if (command.Parameters.Contains(paramName))
                {
                    DbParameter parameter = command.Parameters[paramName];
                    var         val       = GetColumnValue(colInfo, item);
                    parameter.Value = val ?? System.DBNull.Value;
                    _provider.SetParameterDbType(parameter, _tableInfo.Name, colInfo.Name);
                }
            }
        }