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

Disregard parameter names in ExpressionEqualityComparer.GetHashCode #30755

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/EFCore/Query/ExpressionEqualityComparer.cs
Expand Up @@ -30,6 +30,8 @@ private ExpressionEqualityComparer()
/// </summary>
public static ExpressionEqualityComparer Instance { get; } = new();

private List<ParameterExpression>? _lambdaParameters;
aradalvand marked this conversation as resolved.
Show resolved Hide resolved

/// <inheritdoc />
public int GetHashCode(Expression obj)
{
Expand Down Expand Up @@ -110,9 +112,21 @@ public int GetHashCode(Expression obj)
break;

case LambdaExpression lambdaExpression:
_lambdaParameters ??= new();
foreach (var p in lambdaExpression.Parameters)
aradalvand marked this conversation as resolved.
Show resolved Hide resolved
{
_lambdaParameters.Add(p);
}

hash.Add(lambdaExpression.Body, this);
AddListToHash(lambdaExpression.Parameters);
hash.Add(lambdaExpression.ReturnType);

foreach (var p in lambdaExpression.Parameters)
{
_lambdaParameters.Remove(p);
}

break;

case ListInitExpression listInitExpression:
Expand Down Expand Up @@ -161,7 +175,15 @@ public int GetHashCode(Expression obj)
break;

case ParameterExpression parameterExpression:
AddToHashIfNotNull(parameterExpression.Name);
int? index = _lambdaParameters?.IndexOf(parameterExpression);
if (index > -1)
{
hash.Add(index);
aradalvand marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
AddToHashIfNotNull(parameterExpression.Name);
aradalvand marked this conversation as resolved.
Show resolved Hide resolved
}
break;

case RuntimeVariablesExpression runtimeVariablesExpression:
Expand Down