Skip to content

Commit

Permalink
Generate parameter name properly for ExecuteSqlInterpolated
Browse files Browse the repository at this point in the history
Use sql generation helper to generate parameter name to write in sql command.

Resolves #19493
  • Loading branch information
smitpatel committed Feb 11, 2020
1 parent 9477181 commit 4667074
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public virtual RawSqlCommand Build(string sql, IEnumerable<object> parameters)
dbParameter.ParameterName = _sqlGenerationHelper.GenerateParameterName(parameterNameGenerator.GenerateNext());
}

substitutions.Add(dbParameter.ParameterName);
substitutions.Add(_sqlGenerationHelper.GenerateParameterName(dbParameter.ParameterName));
relationalCommandBuilder.AddRawParameter(dbParameter.ParameterName, dbParameter);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ public virtual void Query_with_parameters_interpolated()
Assert.Equal(-1, actual);
}

[ConditionalFact]
public virtual void Query_with_DbParameters_interpolated()
{
var city = CreateDbParameter("city", "London");
var contactTitle = CreateDbParameter( "contactTitle", "Sales Representative");

using var context = CreateContext();
var actual = context.Database
.ExecuteSqlInterpolated(
$@"SELECT COUNT(*) FROM ""Customers"" WHERE ""City"" = {city} AND ""ContactTitle"" = {contactTitle}");

Assert.Equal(-1, actual);
}

[ConditionalFact]
public virtual async Task Executes_stored_procedure_async()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ public override void Query_with_parameters_interpolated()
SELECT COUNT(*) FROM ""Customers"" WHERE ""City"" = @p0 AND ""ContactTitle"" = @p1");
}

public override void Query_with_DbParameters_interpolated()
{
base.Query_with_DbParameters_interpolated();

AssertSql(
@"city='London' (Nullable = false) (Size = 6)
contactTitle='Sales Representative' (Nullable = false) (Size = 20)
SELECT COUNT(*) FROM ""Customers"" WHERE ""City"" = @city AND ""ContactTitle"" = @contactTitle");
}

public override async Task Query_with_parameters_async()
{
await base.Query_with_parameters_async();
Expand Down

0 comments on commit 4667074

Please sign in to comment.