/// <summary> /// Called when [next]. /// </summary> /// <param name="builder">The builder.</param> /// <exception cref="ArgumentNullException">builder.</exception> /// <exception cref="NullReferenceException"> /// Configuration /// or /// Query. /// </exception> public void OnNext(IDataCommandBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (builder.Configuration is null) { throw new NullReferenceException(nameof(builder.Configuration)); } if (builder.Configuration.Query is null) { throw new NullReferenceException(nameof(builder.Configuration.Query)); } if (this.Connection.State != ConnectionState.Open) { this.autoCommit = true; this.Connection.Open(); this.transaction = this.connection .InnerConnection .BeginTransaction(this.il); } if (this.transaction == null) { this.transaction = this.connection .InnerConnection .BeginTransaction(this.il); } if (builder.Configuration.Query == null) { builder.Configuration.Query = this.SqlDialect.CreateBuilder(); } if (builder.Command == null) { builder.Command = this.CreateCommand(); } builder.Configuration.ParameterPrefix = this.SqlDialect.ParameterPrefixToken; builder.ApplyConfiguration(); }
internal static IDataCommand ApplyConfiguration( this IDataCommandBuilder builder) { Check.NotNull(nameof(builder), builder); Check.NotNull(nameof(builder.Command), builder.Command); Check.NotNull(nameof(builder.Configuration), builder.Configuration); Check.NotNull(nameof(builder.Configuration.Query), builder.Configuration.Query); var cfg = builder.Configuration; switch (builder.Configuration.SetType) { case ParameterSetType.List: return(builder.Command.ApplyParameters( cfg.Query, cfg.ParameterList, cfg.ParameterPrefix)); case ParameterSetType.Lookup: return(builder.Command.ApplyParameters( cfg.Query, cfg.ParameterLookup, cfg.ParameterPrefix)); case ParameterSetType.TypedList: return(builder.Command.ApplyParameters( cfg.Query, cfg.TypedParameterList, cfg.ParameterPrefix)); case ParameterSetType.TypedLookup: return(builder.Command.ApplyParameters( cfg.Query, cfg.TypedParameterLookup, cfg.ParameterPrefix)); case ParameterSetType.None: { var cmd = builder.Command; cmd.Type = CommandType.Text; cmd.Text = cfg.Query.ToString(true); return(cmd); } } throw new NotSupportedException(ParameterSetType.None.ToString()); }