sql parameters cleared after executing the command
This commit is contained in:
@@ -39,6 +39,8 @@
|
|||||||
sqlCommand.Parameters.AddRange(command.Parameters);
|
sqlCommand.Parameters.AddRange(command.Parameters);
|
||||||
|
|
||||||
rowsAffected = sqlCommand.ExecuteNonQuery();
|
rowsAffected = sqlCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
sqlCommand.Parameters.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +64,8 @@
|
|||||||
|
|
||||||
using (FluentSQLReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess))
|
using (FluentSQLReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess))
|
||||||
{
|
{
|
||||||
|
sqlCommand.Parameters.Clear();
|
||||||
|
|
||||||
while (sqlReader.Read())
|
while (sqlReader.Read())
|
||||||
{
|
{
|
||||||
yield return expression(sqlReader);
|
yield return expression(sqlReader);
|
||||||
@@ -90,6 +94,8 @@
|
|||||||
|
|
||||||
var scalarObject = sqlCommand.ExecuteScalar();
|
var scalarObject = sqlCommand.ExecuteScalar();
|
||||||
|
|
||||||
|
sqlCommand.Parameters.Clear();
|
||||||
|
|
||||||
if (scalarObject is T scalarValue)
|
if (scalarObject is T scalarValue)
|
||||||
{
|
{
|
||||||
scalarResult = scalarValue;
|
scalarResult = scalarValue;
|
||||||
|
|||||||
@@ -10,19 +10,19 @@
|
|||||||
public class FluentSQLCommand : IFluentSQLCommand
|
public class FluentSQLCommand : IFluentSQLCommand
|
||||||
{
|
{
|
||||||
private readonly FluentSQL fluentSql;
|
private readonly FluentSQL fluentSql;
|
||||||
private readonly ICollection<SqlParameter> parameters;
|
private readonly IDictionary<string, SqlParameter> parameters;
|
||||||
|
|
||||||
public FluentSQLCommand(FluentSQL fluentSql, string commandText)
|
public FluentSQLCommand(FluentSQL fluentSql, string commandText)
|
||||||
{
|
{
|
||||||
this.fluentSql = fluentSql.EnsureNotNull();
|
this.fluentSql = fluentSql.EnsureNotNull();
|
||||||
this.CommandText = commandText.EnsureNotNullOrWhiteSpace();
|
this.CommandText = commandText.EnsureNotNullOrWhiteSpace();
|
||||||
this.parameters = new List<SqlParameter>();
|
this.parameters = new Dictionary<string, SqlParameter>();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal string CommandText { get; }
|
internal string CommandText { get; }
|
||||||
|
|
||||||
internal SqlParameter[] Parameters
|
internal SqlParameter[] Parameters
|
||||||
=> this.parameters.ToArray();
|
=> this.parameters.Values.ToArray();
|
||||||
|
|
||||||
public int ExecuteNonQuery()
|
public int ExecuteNonQuery()
|
||||||
=> this.fluentSql.ExecuteNonQuery(this);
|
=> this.fluentSql.ExecuteNonQuery(this);
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
var parameter = new SqlParameter(name, value);
|
var parameter = new SqlParameter(name, value);
|
||||||
|
|
||||||
this.parameters.Add(parameter);
|
this.parameters[name] = parameter;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user