/// <summary> /// Adds <see cref="IDatabasePropertyMapper"/> parameter <paramref name="when"/> <c>true</c>. /// </summary> /// <typeparam name="T">The parameter <see cref="Type"/>.</typeparam> /// <param name="when">Adds the parameter when <c>true</c>.</param> /// <param name="propertyMapper">The <see cref="IDatabasePropertyMapper"/>.</param> /// <param name="value">The parameter value.</param> /// <param name="direction">The <see cref="ParameterDirection"/> (default to <see cref="ParameterDirection.Input"/>).</param> /// <returns>The current <see cref="DatabaseParameters"/> instance to support chaining (fluent interface).</returns> public DatabaseParameters ParamWhen <T>(bool when, IDatabasePropertyMapper propertyMapper, Func <T> value, ParameterDirection direction = ParameterDirection.Input) { if (when) { Param(propertyMapper, value.Invoke(), direction); } return(this); }
/// <summary> /// Adds a <see cref="IDatabasePropertyMapper"/> parameter. /// </summary> /// <param name="propertyMapper">The <see cref="IDatabasePropertyMapper"/>.</param> /// <param name="value">The parameter value.</param> /// <param name="direction">The <see cref="ParameterDirection"/> (default to <see cref="ParameterDirection.Input"/>).</param> /// <returns>The current <see cref="DatabaseParameters"/> instance to support chaining (fluent interface).</returns> public DatabaseParameters Param(IDatabasePropertyMapper propertyMapper, object value, ParameterDirection direction = ParameterDirection.Input) { if (propertyMapper == null) { throw new ArgumentNullException(nameof(propertyMapper)); } var val = propertyMapper.Converter == null ? value : propertyMapper.Converter.ConvertToDest(value); if (propertyMapper.DestDbType.HasValue) { AddParameter(propertyMapper.DestParameterName, val, propertyMapper.DestDbType.Value, direction); } else { AddParameter(propertyMapper.DestParameterName, val, direction); } return(this); }
/// <summary> /// Adds <see cref="IDatabasePropertyMapper"/> parameter when invoked <paramref name="with"/> a non-default value and converts the wildcard for the database. /// </summary> /// <param name="with">The value <b>with</b> which to verify is non-default.</param> /// <param name="propertyMapper">The <see cref="IDatabasePropertyMapper"/>.</param> /// <param name="value">The parameter value; where not specified the <paramref name="with"/> vaue will be used.</param> /// <param name="direction">The <see cref="ParameterDirection"/> (default to <see cref="ParameterDirection.Input"/>).</param> /// <returns>The current <see cref="DatabaseParameters"/> instance to support chaining (fluent interface).</returns> public DatabaseParameters ParamWithWildcard(string with, IDatabasePropertyMapper propertyMapper, Func <string> value = null, ParameterDirection direction = ParameterDirection.Input) { return(ParamWith(with, propertyMapper, value ?? (() => this.DatabaseCommand.Database.Wildcard.Replace(with)), direction)); }
/// <summary> /// Adds <see cref="IDatabasePropertyMapper"/> parameter when invoked <paramref name="with"/> a non-default value. /// </summary> /// <typeparam name="T">The parameter <see cref="Type"/>.</typeparam> /// <param name="with">The value <b>with</b> which to verify is non-default.</param> /// <param name="propertyMapper">The <see cref="IDatabasePropertyMapper"/>.</param> /// <param name="value">The parameter value; where not specified the <paramref name="with"/> vaue will be used.</param> /// <param name="direction">The <see cref="ParameterDirection"/> (default to <see cref="ParameterDirection.Input"/>).</param> /// <returns>The current <see cref="DatabaseParameters"/> instance to support chaining (fluent interface).</returns> public DatabaseParameters ParamWith <T>(T with, IDatabasePropertyMapper propertyMapper, Func <T> value = null, ParameterDirection direction = ParameterDirection.Input) { return(ParamWhen(Comparer <T> .Default.Compare(with, default(T)) != 0 && Comparer <T> .Default.Compare((T)with, default(T)) != 0, propertyMapper, value ?? (() => with), direction)); }