Skip to content
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 @@ -31,7 +31,7 @@ private readonly IDictionary<FromSqlExpression, Expression> _visitedFromSqlExpre
/// <see cref="ISqlGenerationHelper.GenerateParameterName(string)" /> (i.e. they're prefixed), since
/// <see cref="DbParameter.ParameterName" /> can be prefixed or not.
/// </summary>
private readonly HashSet<string> _prefixedParameterNames = [];
private readonly HashSet<string> _prefixedParameterNames = new(StringComparer.OrdinalIgnoreCase);

private readonly Dictionary<string, SqlParameterExpression> _sqlParameters = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1529,13 +1529,39 @@ public override async Task Using_same_parameter_twice_in_query_generates_one_sql
AssertSql();
}

public override async Task Two_parameters_with_same_name_get_uniquified(bool async)
{
// Concat with conversion, issue #34963.
await AssertTranslationFailed(() => base.Using_same_parameter_twice_in_query_generates_one_sql_parameter(async));
public override Task Two_parameters_with_same_name_get_uniquified(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Two_parameters_with_same_name_get_uniquified(async);

AssertSql();
}
AssertSql(
"""
@customerId='ANATR'
@customerId0='ALFKI'

SELECT VALUE c
FROM root c
WHERE ((c["id"] = @customerId) OR (c["id"] = @customerId0))
""");
});

public override Task Two_parameters_with_same_case_insensitive_name_get_uniquified(bool async)
=> Fixture.NoSyncTest(
async, async a =>
{
await base.Two_parameters_with_same_case_insensitive_name_get_uniquified(async);

AssertSql(
"""
@customerID='ANATR'
@customerId='ALFKI'

SELECT VALUE c
FROM root c
WHERE ((c["id"] = @customerID) OR (c["id"] = @customerId))
""");
});

public override async Task Where_Queryable_ToList_Count(bool async)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1327,16 +1327,27 @@ public virtual Task Using_same_parameter_twice_in_query_generates_one_sql_parame
.Select(c => c.CustomerID));
}

private readonly string customerId = "ALFKI";

[ConditionalTheory, MemberData(nameof(IsAsyncData))]
public virtual Task Two_parameters_with_same_name_get_uniquified(bool async)
{
var i = 10;
var customerId = "ANATR";

return AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => c.CustomerID == customerId || c.CustomerID == this.customerId));
}

[ConditionalTheory, MemberData(nameof(IsAsyncData))]
public virtual Task Two_parameters_with_same_case_insensitive_name_get_uniquified(bool async)
{
var customerID = "ANATR";

// i+1 and i+2 each get parameterized using the same parameter name (since they're complex expressions).
// This exercises that query parameters are properly uniquified.
// Note the parameter names differ only by case (customerID vs. customerId)
return AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => (c.CustomerID + (i + 1)) + (c.CustomerID + (i + 2)) == "ALFKI11ALFKI12"));
ss => ss.Set<Customer>().Where(c => c.CustomerID == customerID || c.CustomerID == customerId));
}

[ConditionalTheory, MemberData(nameof(IsAsyncData))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1704,19 +1704,33 @@ WHERE CAST(@i AS nvarchar(max)) + [c].[CustomerID] + CAST(@i AS nvarchar(max)) =
""");
}

[ConditionalTheory]
public override async Task Two_parameters_with_same_name_get_uniquified(bool async)
{
await base.Two_parameters_with_same_name_get_uniquified(async);

AssertSql(
"""
@p='11'
@p0='12'
@customerId='ANATR' (Size = 5) (DbType = StringFixedLength)
@customerId0='ALFKI' (Size = 5) (DbType = StringFixedLength)

SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE [c].[CustomerID] = @customerId OR [c].[CustomerID] = @customerId0
""");
}

public override async Task Two_parameters_with_same_case_insensitive_name_get_uniquified(bool async)
{
await base.Two_parameters_with_same_case_insensitive_name_get_uniquified(async);

AssertSql(
"""
@customerID='ANATR' (Size = 5) (DbType = StringFixedLength)
@customerId0='ALFKI' (Size = 5) (DbType = StringFixedLength)

SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE [c].[CustomerID] + CAST(@p AS nvarchar(max)) + [c].[CustomerID] + CAST(@p0 AS nvarchar(max)) = N'ALFKI11ALFKI12'
WHERE [c].[CustomerID] = @customerID OR [c].[CustomerID] = @customerId0
""");
}

Expand Down
Loading