diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs index dde4e8ad491..3d23e2430dc 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs @@ -392,7 +392,7 @@ private bool Equals(TableReferenceExpression tableReferenceExpression) /// public override int GetHashCode() - => Alias.GetHashCode(); + => 0; } private sealed class ConcreteColumnExpression : ColumnExpression diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 088b509aaa8..f11cffd8480 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Runtime.CompilerServices; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Query.Internal; @@ -3499,54 +3500,6 @@ private bool Equals(SelectExpression selectExpression) /// public override int GetHashCode() - { - var hash = new HashCode(); - hash.Add(base.GetHashCode()); - - foreach (var projection in _projection) - { - hash.Add(projection); - } - - foreach (var projection in _clientProjections) - { - hash.Add(projection); - } - - foreach (var (projectionMember, expression) in _projectionMapping) - { - hash.Add(projectionMember); - hash.Add(expression); - } - - foreach (var tag in Tags) - { - hash.Add(tag); - } - - foreach (var table in _tables) - { - hash.Add(table); - } - - hash.Add(Predicate); - - foreach (var groupingKey in _groupBy) - { - hash.Add(groupingKey); - } - - hash.Add(Having); - - foreach (var ordering in _orderings) - { - hash.Add(ordering); - } - - hash.Add(Offset); - hash.Add(Limit); - hash.Add(IsDistinct); - - return hash.ToHashCode(); - } + // Since equality above is reference equality, hash code can also be based on reference. + => RuntimeHelpers.GetHashCode(this); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs b/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs index 2490984ddfd..768ceacd41b 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/TableExpressionBase.cs @@ -62,5 +62,5 @@ private bool Equals(TableExpressionBase tableExpressionBase) /// public override int GetHashCode() - => HashCode.Combine(Alias); + => 0; }