diff --git a/src/EFCore/ChangeTracking/ValueComparer`.cs b/src/EFCore/ChangeTracking/ValueComparer`.cs index d6eb5da40d8..a8326582ce7 100644 --- a/src/EFCore/ChangeTracking/ValueComparer`.cs +++ b/src/EFCore/ChangeTracking/ValueComparer`.cs @@ -263,16 +263,18 @@ public override LambdaExpression ObjectEqualsExpression var left = Parameter(typeof(object), "left"); var right = Parameter(typeof(object), "right"); + var remappedEquals = ReplacingExpressionVisitor.Replace( + EqualsExpression.Parameters.ToList(), + [Convert(left, typeof(T)), Convert(right, typeof(T))], + EqualsExpression.Body); + _objectEqualsExpression = Lambda>( Condition( Equal(left, Constant(null)), Equal(right, Constant(null)), AndAlso( NotEqual(right, Constant(null)), - Invoke( - EqualsExpression, - Convert(left, typeof(T)), - Convert(right, typeof(T))))), + remappedEquals)), left, right); }