Example #1
0
        /// <summary>
        /// Sets the parameter direction to Output and registers the call back to get the value.
        /// </summary>
        /// <param name="callback">The callback used to get the out value.</param>
        /// <returns>A fluent <see langword="interface"/> to a data command parameter.</returns>
        public IDataParameter <TValue> Output(Action <TValue> callback)
        {
            // set direction output only if not already set
            if (!_hasDirection)
            {
                _parameter.Direction = _hasValue ? ParameterDirection.InputOutput : ParameterDirection.Output;
            }

            // output parameters must have a size, default to MAX
            if (!_hasSize)
            {
                _parameter.Size = -1;
            }

            _dataCommand.RegisterCallback(_parameter, callback);

            return(this);
        }
        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);
        }
Example #3
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);
        }