Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate parameter name properly for ExecuteSqlInterpolated #19839

Merged
merged 1 commit into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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