diff --git a/src/EFCore.Relational/Query/SqlExpressions/TableValuedFunctionExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/TableValuedFunctionExpression.cs
index 7d5a2efc1fa..996be3e476e 100644
--- a/src/EFCore.Relational/Query/SqlExpressions/TableValuedFunctionExpression.cs
+++ b/src/EFCore.Relational/Query/SqlExpressions/TableValuedFunctionExpression.cs
@@ -120,7 +120,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
/// The property of the result.
/// This expression if no children changed, or an expression with the updated children.
public virtual TableValuedFunctionExpression Update(IReadOnlyList arguments)
- => !arguments.SequenceEqual(Arguments)
+ => !arguments.SequenceEqual(Arguments, ReferenceEqualityComparer.Instance)
? new TableValuedFunctionExpression(Alias, Name, Schema, IsBuiltIn, arguments, Annotations)
: this;
diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
index e188ba9819a..741b8014b02 100644
--- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
+++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
@@ -1253,7 +1253,7 @@ public virtual Task Projection_select_correct_table_in_subquery_when_materializa
ss => (from l2 in ss.Set()
join l1 in ss.Set() on l2.Level1_Required_Id equals l1.Id
join l3 in ss.Set() on l1.Id equals l3.Level2_Required_Id
- //where l1.Name == "L1 03"
+ //where l1.Name == "L1 03"
//where l3.Name == "L3 08"
select l1).OrderBy(l1 => l1.Id).Take(3).Select(l1 => l1.Name));
@@ -4028,7 +4028,7 @@ public virtual Task Correlated_projection_with_first(bool async)
x.Id,
Results = x.OneToMany_Optional1.OrderBy(xx => xx.Id).Any()
? x.OneToMany_Optional1.OrderBy(xx => xx.Id).First().OneToMany_Optional2.Select(xx => xx.OneToOne_Required_FK3.Id)
- : new List()
+ : new List()
}),
elementSorter: e => e.Id,
elementAsserter: (e, a) =>
@@ -4042,7 +4042,7 @@ public virtual Task Correlated_projection_with_first(bool async)
public virtual Task Max_in_multi_level_nested_subquery(bool async)
=> AssertQuery(
async,
- ss => ss.Set().Take(2).Select(x => new
+ ss => ss.Set().OrderBy(l1 => l1.Id).Take(2).Select(x => new
{
x.Id,
LevelTwos = x.OneToMany_Optional1.AsQueryable().Select(xx => new
diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs
index 25c3c976185..62de316d529 100644
--- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs
+++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs
@@ -4789,6 +4789,7 @@ public override async Task Max_in_multi_level_nested_subquery(bool async)
FROM (
SELECT TOP(@__p_0) [l].[Id]
FROM [LevelOne] AS [l]
+ ORDER BY [l].[Id]
) AS [l4]
LEFT JOIN (
SELECT [l0].[Id], [l1].[Id] AS [Id0], [l2].[Id] AS [Id1], CASE
diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs
index 4d42d961988..c112aa099a7 100644
--- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs
+++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs
@@ -8274,6 +8274,7 @@ public override async Task Max_in_multi_level_nested_subquery(bool async)
FROM (
SELECT TOP(@__p_0) [l].[Id]
FROM [Level1] AS [l]
+ ORDER BY [l].[Id]
) AS [l6]
LEFT JOIN (
SELECT CASE