public static IDataCommand Parameter(this IDataCommand dataCommand, IEnumerable <DbParameter> parameters)
        {
            foreach (var parameter in parameters)
            {
                dataCommand.Parameter(parameter);
            }

            return(dataCommand);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new parameter with the <see cref="IDataParameter" /> fluent object.
        /// </summary>
        /// <typeparam name="TParameter"></typeparam>
        /// <param name="dataCommand">The <see cref="IDataCommand"/> for this extension method.</param>
        /// <param name="configurator">The <see langword="delegate" />  to configurator the <see cref="IDataParameter" />.</param>
        /// <returns>
        /// A fluent <see langword="interface" /> to the data command.
        /// </returns>
        public static IDataCommand Parameter <TParameter>(this IDataCommand dataCommand, Action <IDataParameter <TParameter> > configurator)
        {
            var parameter = dataCommand.Command.CreateParameter();

            var dataParameter = new DataParameter <TParameter>(dataCommand, parameter);

            configurator(dataParameter);

            return(dataCommand.Parameter(parameter));
        }
        protected IDataCommand AddWhereParams(IDataCommand command)
        {
            string prefix = "@where";

            foreach (var condition in _whereBuilder.QueryConditions.Keys)
            {
                command.Parameter(prefix + condition.Field.FieldName, condition.Value);
            }

            return(command);
        }
        public static IDataCommand Return <TParameter>(this IDataCommand dataCommand, Action <TParameter> callback)
        {
            const string parameterName = "@ReturnValue";

            var parameter = dataCommand.Command.CreateParameter();

            parameter.ParameterName = parameterName;
            parameter.DbType        = typeof(TParameter).GetUnderlyingType().ToDbType();
            parameter.Direction     = ParameterDirection.ReturnValue;

            dataCommand.RegisterCallback(parameter, callback);
            dataCommand.Parameter(parameter);

            return(dataCommand);
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a new out parameter with the specified <paramref name="name" /> and <paramref name="callback" />.
        /// </summary>
        /// <typeparam name="TParameter">The type of the parameter value.</typeparam>
        /// <param name="dataCommand">The <see cref="IDataCommand"/> for this extension method.</param>
        /// <param name="name">The name of the parameter.</param>
        /// <param name="callback">The callback used to get the out value.</param>
        /// <returns>
        /// A fluent <see langword="interface" /> to the data command.
        /// </returns>
        public static IDataCommand ParameterOut <TParameter>(this IDataCommand dataCommand, string name, Action <TParameter> callback)
        {
            var parameter = dataCommand.Command.CreateParameter();

            parameter.ParameterName = name;
            parameter.DbType        = typeof(TParameter).GetUnderlyingType().ToDbType();
            parameter.Direction     = ParameterDirection.Output;
            // output parameters must have a size, default to MAX
            parameter.Size = -1;

            dataCommand.RegisterCallback(parameter, callback);
            dataCommand.Parameter(parameter);

            return(dataCommand);
        }
        public static IDataCommand ParameterOut <TParameter>(this IDataCommand dataCommand, string name, TParameter value, Action <TParameter> callback)
        {
            object innerValue = value;

            var parameter = dataCommand.Command.CreateParameter();

            parameter.ParameterName = name;
            parameter.Value         = innerValue ?? DBNull.Value;
            parameter.DbType        = typeof(TParameter).GetUnderlyingType().ToDbType();
            parameter.Direction     = ParameterDirection.InputOutput;

            dataCommand.RegisterCallback(parameter, callback);
            dataCommand.Parameter(parameter);

            return(dataCommand);
        }
        public static IDataCommand Parameter <TParameter>(this IDataCommand dataCommand, string name, TParameter value)
        {
            // convert to object
            object innerValue = value;

            // handle value type by using actual value
            var valueType = value != null?value.GetType() : typeof(TParameter);

            var parameter = dataCommand.Command.CreateParameter();

            parameter.ParameterName = name;
            parameter.Value         = innerValue ?? DBNull.Value;
            parameter.DbType        = valueType.GetUnderlyingType().ToDbType();
            parameter.Direction     = ParameterDirection.Input;

            return(dataCommand.Parameter(parameter));
        }
        /// <summary>
        /// Adds a new Sql Server structured table-valued parameter with the specified <paramref name="name" /> and <paramref name="dataTable" />.
        /// </summary>
        /// <param name="dataCommand">The <see cref="IDataCommand"/> for this extension method.</param>
        /// <param name="name">The name of the parameter.</param>
        /// <param name="dataTable">The <see cref="DataTable"/> to be added.</param>
        /// <returns>
        /// A fluent <see langword="interface" /> to the data command.
        /// </returns>
        public static IDataCommand SqlParameter(this IDataCommand dataCommand, string name, DataTable dataTable)
        {
            var parameter    = dataCommand.Command.CreateParameter();
            var sqlParameter = parameter as SqlParameter;

            if (sqlParameter == null)
            {
                throw new InvalidOperationException(
                          "SqlParameter only supported by SQL Server.  Make sure DataSession was created with a valid SqlConnection.");
            }

            sqlParameter.ParameterName = name;
            sqlParameter.Value         = dataTable;
            sqlParameter.Direction     = ParameterDirection.Input;
            sqlParameter.SqlDbType     = SqlDbType.Structured;

            return(dataCommand.Parameter(sqlParameter));
        }