diff --git a/src/Microsoft.EntityFrameworkCore.Relational/Query/ExpressionVisitors/Internal/IncludeExpressionVisitor.cs b/src/Microsoft.EntityFrameworkCore.Relational/Query/ExpressionVisitors/Internal/IncludeExpressionVisitor.cs index df7adf4de69..a486526c42f 100644 --- a/src/Microsoft.EntityFrameworkCore.Relational/Query/ExpressionVisitors/Internal/IncludeExpressionVisitor.cs +++ b/src/Microsoft.EntityFrameworkCore.Relational/Query/ExpressionVisitors/Internal/IncludeExpressionVisitor.cs @@ -135,7 +135,7 @@ var targetTableExpression var targetEntityType = navigation.GetTargetType(); var targetTableName = _relationalAnnotationProvider.For(targetEntityType).TableName; - var targetTableAlias = targetTableName[0].ToString().ToLower(); + var targetTableAlias = _queryCompilationContext.CreateUniqueTableAlias(targetTableName[0].ToString().ToLower()); if (!navigation.IsCollection()) { @@ -179,7 +179,7 @@ var materializer selectExpression.Predicate = oldPredicate; selectExpression.RemoveTable(joinExpression); - selectExpression.AddTable(newJoinExpression); + selectExpression.AddTable(newJoinExpression, false); joinExpression = newJoinExpression; } @@ -223,7 +223,7 @@ var principalTable OrderingDirection.Asc); } - var targetSelectExpression = _selectExpressionFactory.Create(); + var targetSelectExpression = _selectExpressionFactory.Create(_queryCompilationContext); targetTableExpression = new TableExpression( @@ -290,8 +290,9 @@ var innerJoinSelectExpression private JoinExpressionBase AdjustJoinExpression( SelectExpression selectExpression, JoinExpressionBase joinExpression) { - var subquery = new SelectExpression(_querySqlGeneratorFactory, joinExpression.Alias); - subquery.AddTable(joinExpression.TableExpression); + var subquery = new SelectExpression(_querySqlGeneratorFactory, _queryCompilationContext) { Alias = joinExpression.Alias }; + // Don't create new alias when adding tables to subquery + subquery.AddTable(joinExpression.TableExpression, false); subquery.IsProjectStar = true; subquery.Predicate = selectExpression.Predicate; diff --git a/src/Microsoft.EntityFrameworkCore.Relational/Query/ExpressionVisitors/RelationalEntityQueryableExpressionVisitor.cs b/src/Microsoft.EntityFrameworkCore.Relational/Query/ExpressionVisitors/RelationalEntityQueryableExpressionVisitor.cs index 99aa116f237..28e88635126 100644 --- a/src/Microsoft.EntityFrameworkCore.Relational/Query/ExpressionVisitors/RelationalEntityQueryableExpressionVisitor.cs +++ b/src/Microsoft.EntityFrameworkCore.Relational/Query/ExpressionVisitors/RelationalEntityQueryableExpressionVisitor.cs @@ -117,7 +117,7 @@ protected override Expression VisitEntityQueryable(Type elementType) var relationalQueryCompilationContext = QueryModelVisitor.QueryCompilationContext; var entityType = _model.FindEntityType(elementType); - var selectExpression = _selectExpressionFactory.Create(); + var selectExpression = _selectExpressionFactory.Create(relationalQueryCompilationContext); QueryModelVisitor.AddQuery(_querySource, selectExpression); diff --git a/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/ISelectExpressionFactory.cs b/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/ISelectExpressionFactory.cs index 0cecedce11e..82e10e17de5 100644 --- a/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/ISelectExpressionFactory.cs +++ b/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/ISelectExpressionFactory.cs @@ -7,8 +7,8 @@ namespace Microsoft.EntityFrameworkCore.Query.Expressions { public interface ISelectExpressionFactory { - SelectExpression Create(); + SelectExpression Create([NotNull]RelationalQueryCompilationContext queryCompilationContext); - SelectExpression Create([NotNull] string alias); + SelectExpression Create([NotNull]RelationalQueryCompilationContext queryCompilationContext, [NotNull] string alias); } } diff --git a/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/SelectExpression.cs b/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/SelectExpression.cs index 4c0837d8dbc..07d03d947a8 100644 --- a/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/SelectExpression.cs +++ b/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/SelectExpression.cs @@ -22,6 +22,7 @@ public class SelectExpression : TableExpressionBase #endif private readonly IQuerySqlGeneratorFactory _querySqlGeneratorFactory; + private readonly RelationalQueryCompilationContext _queryCompilationContext; private readonly List _projection = new List(); private readonly List _tables = new List(); private readonly List _orderBy = new List(); @@ -35,22 +36,28 @@ public class SelectExpression : TableExpressionBase public virtual Expression Predicate { get; [param: CanBeNull] set; } - public SelectExpression([NotNull] IQuerySqlGeneratorFactory querySqlGeneratorFactory) + public SelectExpression([NotNull] IQuerySqlGeneratorFactory querySqlGeneratorFactory, + [NotNull] RelationalQueryCompilationContext queryCompilationContext) : base(null, null) { Check.NotNull(querySqlGeneratorFactory, nameof(querySqlGeneratorFactory)); _querySqlGeneratorFactory = querySqlGeneratorFactory; + _queryCompilationContext = queryCompilationContext; } public SelectExpression( [NotNull] IQuerySqlGeneratorFactory querySqlGeneratorFactory, + [NotNull] RelationalQueryCompilationContext queryCompilationContext, [NotNull] string alias) - : base(null, Check.NotNull(alias, nameof(alias))) + : base(null, null) { Check.NotNull(querySqlGeneratorFactory, nameof(querySqlGeneratorFactory)); _querySqlGeneratorFactory = querySqlGeneratorFactory; + _queryCompilationContext = queryCompilationContext; + // When assigning alias to select expression make it unique + Alias = queryCompilationContext.CreateUniqueTableAlias(alias); } public override Type Type => _projection.Count == 1 @@ -62,7 +69,7 @@ public virtual SelectExpression Clone([NotNull] string alias) Check.NotNull(alias, nameof(alias)); var selectExpression - = new SelectExpression(_querySqlGeneratorFactory, alias) + = new SelectExpression(_querySqlGeneratorFactory, _queryCompilationContext, alias) { _limit = _limit, _offset = _offset, @@ -84,13 +91,32 @@ var selectExpression public virtual bool IsProjectStar { get; set; } - public virtual void AddTable([NotNull] TableExpressionBase tableExpression) - => _tables.Add(Check.NotNull(tableExpression, nameof(tableExpression))); + public virtual void AddTable([NotNull] TableExpressionBase tableExpression, bool createUniqueAlias = true) + { + Check.NotNull(tableExpression, nameof(tableExpression)); + + if (createUniqueAlias) + { + tableExpression.Alias = _queryCompilationContext.CreateUniqueTableAlias(tableExpression.Alias); + } + _tables.Add(tableExpression); + } public virtual void AddTables([NotNull] IEnumerable tableExpressions) - => _tables.AddRange(Check.NotNull(tableExpressions, nameof(tableExpressions))); + { + Check.NotNull(tableExpressions, nameof(tableExpressions)); - public virtual void ClearTables() => _tables.Clear(); + // Multiple tables are added while moving current select expression inside subquery hence it does not need to generate unique alias + foreach (var tableExpression in tableExpressions.ToList()) + { + AddTable(tableExpression, false); + } + } + + public virtual void ClearTables() + { + _tables.Clear(); + } public virtual bool IsCorrelated() => new CorrelationFindingExpressionVisitor().IsCorrelated(this); @@ -229,7 +255,7 @@ public virtual SelectExpression PushDownSubquery() { _subqueryDepth++; - var subquery = new SelectExpression(_querySqlGeneratorFactory, SystemAliasPrefix + _subqueryDepth); + var subquery = new SelectExpression(_querySqlGeneratorFactory, _queryCompilationContext, SystemAliasPrefix); var columnAliasCounter = 0; @@ -277,7 +303,7 @@ public virtual SelectExpression PushDownSubquery() ClearProjection(); ClearOrderBy(); - AddTable(subquery); + AddTable(subquery, false); return subquery; } @@ -382,7 +408,7 @@ var projectionIndex if (alias != null) { - foreach (var orderByAliasExpression + foreach (var orderByAliasExpression in _orderBy.Select(o => o.Expression).OfType()) { if (orderByAliasExpression.TryGetColumnExpression() == null) @@ -625,8 +651,6 @@ public virtual void AddCrossJoin( Check.NotNull(tableExpression, nameof(tableExpression)); Check.NotNull(projection, nameof(projection)); - tableExpression.Alias = CreateUniqueTableAlias(tableExpression.Alias); - _tables.Add(new CrossJoinExpression(tableExpression)); _projection.AddRange(projection); } @@ -638,8 +662,6 @@ public virtual void AddLateralJoin( Check.NotNull(tableExpression, nameof(tableExpression)); Check.NotNull(projection, nameof(projection)); - tableExpression.Alias = CreateUniqueTableAlias(tableExpression.Alias); - _tables.Add(new LateralJoinExpression(tableExpression)); _projection.AddRange(projection); } @@ -658,8 +680,6 @@ public virtual JoinExpressionBase AddInnerJoin( Check.NotNull(tableExpression, nameof(tableExpression)); Check.NotNull(projection, nameof(projection)); - tableExpression.Alias = CreateUniqueTableAlias(tableExpression.Alias); - var innerJoinExpression = new InnerJoinExpression(tableExpression); _tables.Add(innerJoinExpression); @@ -682,8 +702,6 @@ public virtual JoinExpressionBase AddOuterJoin( Check.NotNull(tableExpression, nameof(tableExpression)); Check.NotNull(projection, nameof(projection)); - tableExpression.Alias = CreateUniqueTableAlias(tableExpression.Alias); - var outerJoinExpression = new LeftOuterJoinExpression(tableExpression); _tables.Add(outerJoinExpression); @@ -692,31 +710,6 @@ public virtual JoinExpressionBase AddOuterJoin( return outerJoinExpression; } - public virtual string CreateUniqueTableAlias() - => CreateUniqueTableAlias(SystemAliasPrefix); - - private string CreateUniqueTableAlias(string currentAlias) - { - Debug.Assert(currentAlias != null); - - var uniqueAlias = currentAlias; - var counter = 0; - - int _; - if (currentAlias.StartsWith(SystemAliasPrefix, StringComparison.Ordinal) - && int.TryParse(currentAlias.Substring(1), out _)) - { - currentAlias = SystemAliasPrefix; - } - - while (_tables.Any(t => string.Equals(t.Alias, uniqueAlias, StringComparison.OrdinalIgnoreCase))) - { - uniqueAlias = currentAlias + counter++; - } - - return uniqueAlias; - } - private string CreateUniqueProjectionAlias(string currentAlias) { var uniqueAlias = currentAlias ?? "A"; diff --git a/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/SelectExpressionFactory.cs b/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/SelectExpressionFactory.cs index 9647bccaa19..68af7604f13 100644 --- a/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/SelectExpressionFactory.cs +++ b/src/Microsoft.EntityFrameworkCore.Relational/Query/Expressions/SelectExpressionFactory.cs @@ -18,12 +18,13 @@ public SelectExpressionFactory([NotNull] IQuerySqlGeneratorFactory querySqlGener _querySqlGeneratorFactory = querySqlGeneratorFactory; } - public virtual SelectExpression Create() - => new SelectExpression(_querySqlGeneratorFactory); + public virtual SelectExpression Create(RelationalQueryCompilationContext queryCompilationContext) + => new SelectExpression(_querySqlGeneratorFactory, queryCompilationContext); - public virtual SelectExpression Create(string alias) + public virtual SelectExpression Create(RelationalQueryCompilationContext queryCompilationContext, string alias) => new SelectExpression( _querySqlGeneratorFactory, + queryCompilationContext, Check.NotEmpty(alias, nameof(alias))); } } diff --git a/src/Microsoft.EntityFrameworkCore.Relational/Query/Internal/RelationalResultOperatorHandler.cs b/src/Microsoft.EntityFrameworkCore.Relational/Query/Internal/RelationalResultOperatorHandler.cs index 007cf0de87b..a735b697cf6 100644 --- a/src/Microsoft.EntityFrameworkCore.Relational/Query/Internal/RelationalResultOperatorHandler.cs +++ b/src/Microsoft.EntityFrameworkCore.Relational/Query/Internal/RelationalResultOperatorHandler.cs @@ -165,7 +165,7 @@ var predicate if (predicate != null) { - var innerSelectExpression = handlerContext.SelectExpressionFactory.Create(); + var innerSelectExpression = handlerContext.SelectExpressionFactory.Create(handlerContext.QueryModelVisitor.QueryCompilationContext); innerSelectExpression.AddTables(handlerContext.SelectExpression.Tables); innerSelectExpression.Predicate = Expression.Not(predicate); @@ -194,7 +194,7 @@ var predicate private static Expression HandleAny(HandlerContext handlerContext) { - var innerSelectExpression = handlerContext.SelectExpressionFactory.Create(); + var innerSelectExpression = handlerContext.SelectExpressionFactory.Create(handlerContext.QueryModelVisitor.QueryCompilationContext); innerSelectExpression.AddTables(handlerContext.SelectExpression.Tables); innerSelectExpression.Predicate = handlerContext.SelectExpression.Predicate; @@ -235,14 +235,14 @@ var filteringVisitor if (entityType != null) { - var outterSelectExpression = handlerContext.SelectExpressionFactory.Create(); + var outterSelectExpression = handlerContext.SelectExpressionFactory.Create(handlerContext.QueryModelVisitor.QueryCompilationContext); outterSelectExpression.SetProjectionExpression(Expression.Constant(1)); var collectionSelectExpression - = handlerContext.SelectExpression.Clone(outterSelectExpression.CreateUniqueTableAlias()); + = handlerContext.SelectExpression.Clone(handlerContext.QueryModelVisitor.QueryCompilationContext.CreateUniqueTableAlias()); outterSelectExpression.AddTable(collectionSelectExpression); - itemSelectExpression.Alias = outterSelectExpression.CreateUniqueTableAlias(); + itemSelectExpression.Alias = handlerContext.QueryModelVisitor.QueryCompilationContext.CreateUniqueTableAlias(); var joinExpression = outterSelectExpression.AddInnerJoin(itemSelectExpression); foreach (var property in entityType.FindPrimaryKey().Properties) @@ -333,7 +333,7 @@ private static Expression HandleDefaultIfEmpty(HandlerContext handlerContext) selectExpression.ClearTables(); - var emptySelectExpression = handlerContext.SelectExpressionFactory.Create("empty"); + var emptySelectExpression = handlerContext.SelectExpressionFactory.Create(handlerContext.QueryModelVisitor.QueryCompilationContext, "empty"); emptySelectExpression.AddToProjection(new AliasExpression("empty", Expression.Constant(null))); selectExpression.AddTable(emptySelectExpression); diff --git a/src/Microsoft.EntityFrameworkCore.Relational/Query/RelationalQueryCompilationContext.cs b/src/Microsoft.EntityFrameworkCore.Relational/Query/RelationalQueryCompilationContext.cs index 3e5fbf7a68c..cc35604d3d4 100644 --- a/src/Microsoft.EntityFrameworkCore.Relational/Query/RelationalQueryCompilationContext.cs +++ b/src/Microsoft.EntityFrameworkCore.Relational/Query/RelationalQueryCompilationContext.cs @@ -3,7 +3,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Text.RegularExpressions; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -20,6 +22,10 @@ public class RelationalQueryCompilationContext : QueryCompilationContext private readonly List _relationalQueryModelVisitors = new List(); + private const string SystemAliasPrefix = "t"; + private Regex NumericEnding = new Regex("[0-9]*$", default(RegexOptions), TimeSpan.FromMilliseconds(1000.0)); + private readonly ISet _tableAliasSet = new HashSet(); + public RelationalQueryCompilationContext( [NotNull] IModel model, [NotNull] ISensitiveDataLogger logger, @@ -78,5 +84,30 @@ public virtual SelectExpression FindSelectExpression([NotNull] IQuerySource quer select selectExpression) .First(); } + + public virtual string CreateUniqueTableAlias() + => CreateUniqueTableAlias(SystemAliasPrefix); + + public virtual string CreateUniqueTableAlias([NotNull] string currentAlias) + { + Debug.Assert(currentAlias != null); + + if (string.IsNullOrEmpty(currentAlias)) + { + return currentAlias; + } + + currentAlias = NumericEnding.Replace(currentAlias, ""); + var uniqueAlias = currentAlias; + var counter = 0; + + while (_tableAliasSet.Any(t => string.Equals(t, uniqueAlias, StringComparison.OrdinalIgnoreCase))) + { + uniqueAlias = currentAlias + counter++; + } + + _tableAliasSet.Add(uniqueAlias); + return uniqueAlias; + } } } diff --git a/test/Microsoft.EntityFrameworkCore.FunctionalTests/IncludeTestBase.cs b/test/Microsoft.EntityFrameworkCore.FunctionalTests/IncludeTestBase.cs index 44437e3ba20..5de7cf04458 100644 --- a/test/Microsoft.EntityFrameworkCore.FunctionalTests/IncludeTestBase.cs +++ b/test/Microsoft.EntityFrameworkCore.FunctionalTests/IncludeTestBase.cs @@ -1157,7 +1157,7 @@ public virtual void Include_with_complex_projection() } } - [Fact] + [Fact] public virtual void Include_with_take() { using (var context = CreateContext()) diff --git a/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/QueryLoggingSqlServerTest.cs b/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/QueryLoggingSqlServerTest.cs index 63685993f00..61d21bbd0f0 100644 --- a/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/QueryLoggingSqlServerTest.cs +++ b/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/QueryLoggingSqlServerTest.cs @@ -92,13 +92,13 @@ ORDER BY [c].[CustomerID] relatedValueBuffers: IEnumerable _Query( queryContext: queryContext, shaperCommandContext: SelectExpression: - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] + SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] + FROM [Orders] AS [o0] INNER JOIN ( SELECT DISTINCT [c].[CustomerID] FROM [Customers] AS [c] - ) AS [c] ON [o].[CustomerID] = [c].[CustomerID] - ORDER BY [c].[CustomerID] + ) AS [c0] ON [o0].[CustomerID] = [c0].[CustomerID] + ORDER BY [c0].[CustomerID] , queryIndex: 1 ) diff --git a/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/QuerySqlServerTest.cs b/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/QuerySqlServerTest.cs index 0194e73dfbd..9d7e83bb480 100644 --- a/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/QuerySqlServerTest.cs +++ b/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/QuerySqlServerTest.cs @@ -28,39 +28,39 @@ public override void Default_if_empty_top_level() base.Default_if_empty_top_level(); Assert.Equal( - @"SELECT [t0].[EmployeeID], [t0].[City], [t0].[Country], [t0].[FirstName], [t0].[ReportsTo], [t0].[Title] + @"SELECT [t].[EmployeeID], [t].[City], [t].[Country], [t].[FirstName], [t].[ReportsTo], [t].[Title] FROM ( SELECT NULL AS [empty] -) AS [empty] +) AS [empty0] LEFT JOIN ( SELECT [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] FROM [Employees] AS [c] WHERE [c].[EmployeeID] = -1 -) AS [t0] ON 1 = 1", +) AS [t] ON 1 = 1", Sql); } public override void Default_if_empty_top_level_positive() { base.Default_if_empty_top_level_positive(); - + Assert.Equal( - @"SELECT [t0].[EmployeeID], [t0].[City], [t0].[Country], [t0].[FirstName], [t0].[ReportsTo], [t0].[Title] + @"SELECT [t].[EmployeeID], [t].[City], [t].[Country], [t].[FirstName], [t].[ReportsTo], [t].[Title] FROM ( SELECT NULL AS [empty] -) AS [empty] +) AS [empty0] LEFT JOIN ( SELECT [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] FROM [Employees] AS [c] WHERE [c].[EmployeeID] > 0 -) AS [t0] ON 1 = 1", +) AS [t] ON 1 = 1", Sql); } public override void Default_if_empty_top_level_arg() { base.Default_if_empty_top_level_arg(); - + Assert.Equal( @"SELECT [c].[EmployeeID], [c].[City], [c].[Country], [c].[FirstName], [c].[ReportsTo], [c].[Title] FROM [Employees] AS [c] @@ -73,15 +73,15 @@ public override void Default_if_empty_top_level_projection() base.Default_if_empty_top_level_projection(); Assert.Equal( - @"SELECT [t0].[EmployeeID] + @"SELECT [t].[EmployeeID] FROM ( SELECT NULL AS [empty] -) AS [empty] +) AS [empty0] LEFT JOIN ( SELECT [e].[EmployeeID] FROM [Employees] AS [e] WHERE [e].[EmployeeID] = -1 -) AS [t0] ON 1 = 1", +) AS [t] ON 1 = 1", Sql); } @@ -194,11 +194,11 @@ public override void Select_Where_Subquery_Deep_Single() @"SELECT [od].[OrderID], [od].[ProductID], [od].[Discount], [od].[Quantity], [od].[UnitPrice] FROM [Order Details] AS [od] -SELECT [o].[OrderID], [o].[CustomerID] -FROM [Orders] AS [o] +SELECT [o0].[OrderID], [o0].[CustomerID] +FROM [Orders] AS [o0] -SELECT [c].[CustomerID], [c].[City] -FROM [Customers] AS [c]", +SELECT [c0].[CustomerID], [c0].[City] +FROM [Customers] AS [c0]", Sql); } @@ -210,11 +210,11 @@ public override void Select_Where_Subquery_Deep_First() @"SELECT [od].[OrderID], [od].[ProductID], [od].[Discount], [od].[Quantity], [od].[UnitPrice] FROM [Order Details] AS [od] -SELECT [o].[OrderID], [o].[CustomerID] -FROM [Orders] AS [o] +SELECT [o0].[OrderID], [o0].[CustomerID] +FROM [Orders] AS [o0] -SELECT [c].[CustomerID], [c].[City] -FROM [Customers] AS [c]", +SELECT [c0].[CustomerID], [c0].[City] +FROM [Customers] AS [c0]", Sql); } @@ -225,15 +225,15 @@ public override void Where_subquery_anon() Assert.Equal( @"@__p_0: 9 -SELECT [t0].[EmployeeID], [t0].[City], [t0].[Country], [t0].[FirstName], [t0].[ReportsTo], [t0].[Title], [t1].[OrderID], [t1].[CustomerID], [t1].[EmployeeID], [t1].[OrderDate] +SELECT [t].[EmployeeID], [t].[City], [t].[Country], [t].[FirstName], [t].[ReportsTo], [t].[Title], [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate] FROM ( - SELECT TOP(@__p_0) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] - FROM [Employees] AS [e] -) AS [t0] + SELECT TOP(@__p_0) [e0].[EmployeeID], [e0].[City], [e0].[Country], [e0].[FirstName], [e0].[ReportsTo], [e0].[Title] + FROM [Employees] AS [e0] +) AS [t] CROSS JOIN ( - SELECT TOP(1000) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] -) AS [t1]", + SELECT TOP(1000) [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] + FROM [Orders] AS [o0] +) AS [t0]", Sql); } @@ -826,7 +826,7 @@ public override void Distinct_Count() FROM ( SELECT DISTINCT [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] -) AS [t0]", +) AS [t]", Sql); } @@ -840,7 +840,7 @@ public override void Select_Distinct_Count() FROM ( SELECT DISTINCT [c].[City] FROM [Customers] AS [c] -) AS [t0]", +) AS [t]", Sql); } @@ -939,13 +939,13 @@ public override void Take_Skip() @"@__p_0: 10 @__p_1: 5 -SELECT [t0].* +SELECT [t].* FROM ( SELECT TOP(@__p_0) [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] ORDER BY [c].[ContactName] -) AS [t0] -ORDER BY [t0].[ContactName] +) AS [t] +ORDER BY [t].[ContactName] OFFSET @__p_1 ROWS", Sql); } @@ -960,17 +960,17 @@ public override void Take_Skip_Distinct() @"@__p_0: 10 @__p_1: 5 -SELECT DISTINCT [t1].* +SELECT DISTINCT [t0].* FROM ( - SELECT [t0].* + SELECT [t].* FROM ( SELECT TOP(@__p_0) [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] ORDER BY [c].[ContactName] - ) AS [t0] - ORDER BY [t0].[ContactName] + ) AS [t] + ORDER BY [t].[ContactName] OFFSET @__p_1 ROWS -) AS [t1]", +) AS [t0]", Sql); } @@ -984,32 +984,32 @@ public override void Take_Skip_Distinct_Caching() @"@__p_0: 10 @__p_1: 5 -SELECT DISTINCT [t1].* +SELECT DISTINCT [t0].* FROM ( - SELECT [t0].* + SELECT [t].* FROM ( SELECT TOP(@__p_0) [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] ORDER BY [c].[ContactName] - ) AS [t0] - ORDER BY [t0].[ContactName] + ) AS [t] + ORDER BY [t].[ContactName] OFFSET @__p_1 ROWS -) AS [t1] +) AS [t0] @__p_0: 15 @__p_1: 10 -SELECT DISTINCT [t1].* +SELECT DISTINCT [t0].* FROM ( - SELECT [t0].* + SELECT [t].* FROM ( SELECT TOP(@__p_0) [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] ORDER BY [c].[ContactName] - ) AS [t0] - ORDER BY [t0].[ContactName] + ) AS [t] + ORDER BY [t].[ContactName] OFFSET @__p_1 ROWS -) AS [t1]", +) AS [t0]", Sql); } @@ -1029,7 +1029,7 @@ SELECT COUNT(*) FROM ( SELECT DISTINCT TOP(@__p_0) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Orders] AS [o] -) AS [t0]", +) AS [t]", Sql); } @@ -1045,7 +1045,7 @@ SELECT COUNT(*) SELECT DISTINCT TOP(@__p_0) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Orders] AS [o] WHERE [o].[CustomerID] = 'FRANK' -) AS [t0]", +) AS [t]", Sql); } @@ -1086,11 +1086,11 @@ public override void Queryable_simple_anonymous_projection_subquery() Assert.Equal( @"@__p_0: 91 -SELECT [t0].[City] +SELECT [t].[City] FROM ( - SELECT TOP(@__p_0) [c].* - FROM [Customers] AS [c] -) AS [t0]", + SELECT TOP(@__p_0) [c0].* + FROM [Customers] AS [c0] +) AS [t]", Sql); } @@ -1152,12 +1152,12 @@ public override void Take_subquery_projection() Assert.Equal( @"@__p_0: 2 -SELECT [t0].[City] +SELECT [t].[City] FROM ( - SELECT TOP(@__p_0) [c].* - FROM [Customers] AS [c] - ORDER BY [c].[CustomerID] -) AS [t0]", + SELECT TOP(@__p_0) [c0].* + FROM [Customers] AS [c0] + ORDER BY [c0].[CustomerID] +) AS [t]", Sql); } @@ -1173,7 +1173,7 @@ SELECT COUNT(*) SELECT TOP(@__p_0) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM [Orders] AS [o] ORDER BY [o].[OrderID] -) AS [t0]", +) AS [t]", Sql); } @@ -1186,9 +1186,9 @@ public override void Take_OrderBy_Count() SELECT COUNT(*) FROM ( - SELECT TOP(@__p_0) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] -) AS [t0]", + SELECT TOP(@__p_0) [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] + FROM [Orders] AS [o0] +) AS [t]", Sql); } @@ -1400,11 +1400,11 @@ public override void Select_scalar_primitive_after_take() Assert.Equal( @"@__p_0: 9 -SELECT [t0].[EmployeeID] +SELECT [t].[EmployeeID] FROM ( - SELECT TOP(@__p_0) [e].* - FROM [Employees] AS [e] -) AS [t0]", + SELECT TOP(@__p_0) [e0].* + FROM [Employees] AS [e0] +) AS [t]", Sql); } @@ -2053,7 +2053,7 @@ public override void SelectMany_mixed() { base.SelectMany_mixed(); - Assert.Equal(3763, Sql.Replace("\r","").Replace("\n","").Length); // new-line insensitive assertion + Assert.Equal(3763, Sql.Replace("\r", "").Replace("\n", "").Length); // new-line insensitive assertion Assert.StartsWith( @"SELECT [e1].[EmployeeID], [e1].[City], [e1].[Country], [e1].[FirstName], [e1].[ReportsTo], [e1].[Title] FROM [Employees] AS [e1] @@ -2073,11 +2073,11 @@ public override void SelectMany_simple_subquery() Assert.Equal( @"@__p_0: 9 -SELECT [t0].[EmployeeID], [t0].[City], [t0].[Country], [t0].[FirstName], [t0].[ReportsTo], [t0].[Title], [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +SELECT [t].[EmployeeID], [t].[City], [t].[Country], [t].[FirstName], [t].[ReportsTo], [t].[Title], [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM ( - SELECT TOP(@__p_0) [e].[EmployeeID], [e].[City], [e].[Country], [e].[FirstName], [e].[ReportsTo], [e].[Title] - FROM [Employees] AS [e] -) AS [t0] + SELECT TOP(@__p_0) [e0].[EmployeeID], [e0].[City], [e0].[Country], [e0].[FirstName], [e0].[ReportsTo], [e0].[Title] + FROM [Employees] AS [e0] +) AS [t] CROSS JOIN [Customers] AS [c]", Sql); } @@ -2296,14 +2296,14 @@ public override void Join_customers_orders_with_subquery_with_take() Assert.Equal( @"@__p_0: 5 -SELECT [c].[ContactName], [t0].[OrderID] +SELECT [c].[ContactName], [t].[OrderID] FROM [Customers] AS [c] INNER JOIN ( - SELECT TOP(@__p_0) [o2].* - FROM [Orders] AS [o2] - ORDER BY [o2].[OrderID] -) AS [t0] ON [c].[CustomerID] = [t0].[CustomerID] -WHERE [t0].[CustomerID] = 'ALFKI'", + SELECT TOP(@__p_0) [o0].* + FROM [Orders] AS [o0] + ORDER BY [o0].[OrderID] +) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +WHERE [t].[CustomerID] = 'ALFKI'", Sql); } @@ -2359,15 +2359,15 @@ public override void Join_customers_orders_with_subquery_predicate_with_take() Assert.Equal( @"@__p_0: 5 -SELECT [c].[ContactName], [t0].[OrderID] +SELECT [c].[ContactName], [t].[OrderID] FROM [Customers] AS [c] INNER JOIN ( - SELECT TOP(@__p_0) [o2].* - FROM [Orders] AS [o2] - WHERE [o2].[OrderID] > 0 - ORDER BY [o2].[OrderID] -) AS [t0] ON [c].[CustomerID] = [t0].[CustomerID] -WHERE [t0].[CustomerID] = 'ALFKI'", + SELECT TOP(@__p_0) [o0].* + FROM [Orders] AS [o0] + WHERE [o0].[OrderID] > 0 + ORDER BY [o0].[OrderID] +) AS [t] ON [c].[CustomerID] = [t].[CustomerID] +WHERE [t].[CustomerID] = 'ALFKI'", Sql); } @@ -2575,11 +2575,11 @@ public override void GroupJoin_DefaultIfEmpty3() SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] FROM ( - SELECT TOP(@__p_0) [c].* - FROM [Customers] AS [c] -) AS [t0] -LEFT JOIN [Orders] AS [o] ON [t0].[CustomerID] = [o].[CustomerID] -ORDER BY [t0].[CustomerID]", + SELECT TOP(@__p_0) [c0].* + FROM [Customers] AS [c0] +) AS [t] +LEFT JOIN [Orders] AS [o] ON [t].[CustomerID] = [o].[CustomerID] +ORDER BY [t].[CustomerID]", Sql); } @@ -2626,13 +2626,13 @@ public override void GroupJoin_simple_subquery() Assert.Equal( @"@__p_0: 4 -SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate] +SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] FROM [Customers] AS [c] LEFT JOIN ( - SELECT TOP(@__p_0) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] - ORDER BY [o].[OrderID] -) AS [t0] ON [c].[CustomerID] = [t0].[CustomerID] + SELECT TOP(@__p_0) [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] + FROM [Orders] AS [o0] + ORDER BY [o0].[OrderID] +) AS [t] ON [c].[CustomerID] = [t].[CustomerID] ORDER BY [c].[CustomerID]", Sql); } @@ -2657,15 +2657,15 @@ public override void SelectMany_Joined_DefaultIfEmpty() @"SELECT [t1].[OrderID], [t1].[CustomerID], [t1].[EmployeeID], [t1].[OrderDate], [c].[ContactName] FROM [Customers] AS [c] CROSS APPLY ( - SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate] + SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] FROM ( SELECT NULL AS [empty] - ) AS [empty] + ) AS [empty0] LEFT JOIN ( - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] - WHERE [o].[CustomerID] = [c].[CustomerID] - ) AS [t0] ON 1 = 1 + SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] + FROM [Orders] AS [o0] + WHERE [o0].[CustomerID] = [c].[CustomerID] + ) AS [t] ON 1 = 1 ) AS [t1]", Sql); } @@ -2678,15 +2678,15 @@ public override void SelectMany_Joined_DefaultIfEmpty2() @"SELECT [t1].[OrderID], [t1].[CustomerID], [t1].[EmployeeID], [t1].[OrderDate] FROM [Customers] AS [c] CROSS APPLY ( - SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate] + SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate] FROM ( SELECT NULL AS [empty] - ) AS [empty] + ) AS [empty0] LEFT JOIN ( - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] - WHERE [o].[CustomerID] = [c].[CustomerID] - ) AS [t0] ON 1 = 1 + SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] + FROM [Orders] AS [o0] + WHERE [o0].[CustomerID] = [c].[CustomerID] + ) AS [t] ON 1 = 1 ) AS [t1]", Sql); } @@ -2696,13 +2696,13 @@ public override void SelectMany_Joined_Take() base.SelectMany_Joined_Take(); Assert.Equal( - @"SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [c].[ContactName] + @"SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate], [c].[ContactName] FROM [Customers] AS [c] CROSS APPLY ( - SELECT TOP(1000) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] - WHERE [o].[CustomerID] = [c].[CustomerID] -) AS [t0]", + SELECT TOP(1000) [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] + FROM [Orders] AS [o0] + WHERE [o0].[CustomerID] = [c].[CustomerID] +) AS [t]", Sql); } @@ -2713,12 +2713,12 @@ public override void Take_with_single() Assert.Equal( @"@__p_0: 1 -SELECT TOP(2) [t0].* +SELECT TOP(2) [t].* FROM ( SELECT TOP(@__p_0) [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] ORDER BY [c].[CustomerID] -) AS [t0]", +) AS [t]", Sql); } @@ -2729,13 +2729,13 @@ public override void Take_with_single_select_many() Assert.Equal( @"@__p_0: 1 -SELECT TOP(2) [t0].* +SELECT TOP(2) [t].* FROM ( SELECT TOP(@__p_0) [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [o].[OrderID], [o].[CustomerID] AS [c0], [o].[EmployeeID], [o].[OrderDate] FROM [Customers] AS [c] CROSS JOIN [Orders] AS [o] ORDER BY [c].[CustomerID], [o].[OrderID] -) AS [t0]", +) AS [t]", Sql); } @@ -2846,12 +2846,12 @@ public override void Distinct_OrderBy() base.Distinct_OrderBy(); Assert.Equal( - @"SELECT [t0].[Country] + @"SELECT [t].[Country] FROM ( - SELECT DISTINCT [c].[Country] - FROM [Customers] AS [c] -) AS [t0] -ORDER BY [t0].[Country]", + SELECT DISTINCT [c0].[Country] + FROM [Customers] AS [c0] +) AS [t] +ORDER BY [t].[Country]", Sql); } @@ -2860,12 +2860,12 @@ public override void Distinct_OrderBy2() base.Distinct_OrderBy2(); Assert.Equal( - @"SELECT [t0].[CustomerID], [t0].[Address], [t0].[City], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Country], [t0].[Fax], [t0].[Phone], [t0].[PostalCode], [t0].[Region] + @"SELECT [t].[CustomerID], [t].[Address], [t].[City], [t].[CompanyName], [t].[ContactName], [t].[ContactTitle], [t].[Country], [t].[Fax], [t].[Phone], [t].[PostalCode], [t].[Region] FROM ( - SELECT DISTINCT [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] -) AS [t0] -ORDER BY [t0].[CustomerID]", + SELECT DISTINCT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region] + FROM [Customers] AS [c0] +) AS [t] +ORDER BY [t].[CustomerID]", Sql); } @@ -2874,12 +2874,12 @@ public override void Distinct_OrderBy3() base.Distinct_OrderBy3(); Assert.Equal( - @"SELECT [t0].[CustomerID] + @"SELECT [t].[CustomerID] FROM ( - SELECT DISTINCT [c].[CustomerID] - FROM [Customers] AS [c] -) AS [t0] -ORDER BY [t0].[CustomerID]", + SELECT DISTINCT [c0].[CustomerID] + FROM [Customers] AS [c0] +) AS [t] +ORDER BY [t].[CustomerID]", Sql); } @@ -3049,12 +3049,12 @@ public override void Where_primitive() Assert.Equal( @"@__p_0: 9 -SELECT [t0].[EmployeeID] +SELECT [t].[EmployeeID] FROM ( - SELECT TOP(@__p_0) [e].[EmployeeID] - FROM [Employees] AS [e] -) AS [t0] -WHERE [t0].[EmployeeID] = 5", + SELECT TOP(@__p_0) [e0].[EmployeeID] + FROM [Employees] AS [e0] +) AS [t] +WHERE [t].[EmployeeID] = 5", Sql); } @@ -3743,8 +3743,8 @@ SELECT 1 FROM [Customers] AS [c] ORDER BY [c].[CustomerID] -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]", +SELECT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region] +FROM [Customers] AS [c0]", Sql); } @@ -4227,11 +4227,11 @@ public override void OfType_Select() Assert.Equal( @"SELECT TOP(1) [o.Customer].[City] FROM ( - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] -) AS [t0] -INNER JOIN [Customers] AS [o.Customer] ON [t0].[CustomerID] = [o.Customer].[CustomerID] -ORDER BY [t0].[OrderID]", + SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate] + FROM [Orders] AS [o0] +) AS [t] +INNER JOIN [Customers] AS [o.Customer] ON [t].[CustomerID] = [o.Customer].[CustomerID] +ORDER BY [t].[OrderID]", Sql); } @@ -4244,8 +4244,8 @@ public override void OfType_Select_OfType_Select() FROM ( SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate] FROM ( - SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate] - FROM [Orders] AS [o] + SELECT [o2].[OrderID], [o2].[CustomerID], [o2].[EmployeeID], [o2].[OrderDate] + FROM [Orders] AS [o2] ) AS [t0] ) AS [t1] INNER JOIN [Customers] AS [o.Customer] ON [t1].[CustomerID] = [o.Customer].[CustomerID] @@ -4537,17 +4537,17 @@ public override void Take_skip_null_coalesce_operator() Assert.Equal(@"@__p_0: 10 @__p_1: 5 -SELECT DISTINCT [t1].* +SELECT DISTINCT [t0].* FROM ( - SELECT [t0].* + SELECT [t].* FROM ( SELECT TOP(@__p_0) [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] ORDER BY COALESCE([c].[Region], 'ZZ') - ) AS [t0] - ORDER BY COALESCE([t0].[Region], 'ZZ') + ) AS [t] + ORDER BY COALESCE([t].[Region], 'ZZ') OFFSET @__p_1 ROWS -) AS [t1]", +) AS [t0]", Sql); } @@ -4559,7 +4559,7 @@ public override void Select_take_null_coalesce_operator() SELECT TOP(@__p_0) [c].[CustomerID], [c].[CompanyName], COALESCE([c].[Region], 'ZZ') AS [Coalesce] FROM [Customers] AS [c] -ORDER BY [Coalesce]", +ORDER BY [Coalesce]", Sql); } @@ -4573,12 +4573,12 @@ public override void Select_take_skip_null_coalesce_operator() @"@__p_0: 10 @__p_1: 5 -SELECT [t0].* +SELECT [t].* FROM ( SELECT TOP(@__p_0) [c].[CustomerID], [c].[CompanyName], COALESCE([c].[Region], 'ZZ') AS [Coalesce] FROM [Customers] AS [c] ORDER BY [Coalesce] -) AS [t0] +) AS [t] ORDER BY [Coalesce] OFFSET @__p_1 ROWS", Sql); @@ -4594,13 +4594,13 @@ public override void Select_take_skip_null_coalesce_operator2() @"@__p_0: 10 @__p_1: 5 -SELECT [t0].* +SELECT [t].* FROM ( SELECT TOP(@__p_0) [c].[CustomerID], [c].[CompanyName], [c].[Region] FROM [Customers] AS [c] ORDER BY COALESCE([c].[Region], 'ZZ') -) AS [t0] -ORDER BY COALESCE([t0].[Region], 'ZZ') +) AS [t] +ORDER BY COALESCE([t].[Region], 'ZZ') OFFSET @__p_1 ROWS", Sql); } @@ -4615,13 +4615,13 @@ public override void Select_take_skip_null_coalesce_operator3() @"@__p_0: 10 @__p_1: 5 -SELECT [t0].* +SELECT [t].* FROM ( SELECT TOP(@__p_0) [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] ORDER BY COALESCE([c].[Region], 'ZZ') -) AS [t0] -ORDER BY COALESCE([t0].[Region], 'ZZ') +) AS [t] +ORDER BY COALESCE([t].[Region], 'ZZ') OFFSET @__p_1 ROWS", Sql); } diff --git a/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/RowNumberPagingTest.cs b/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/RowNumberPagingTest.cs index 61c4eb555a4..94120ee9318 100644 --- a/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/RowNumberPagingTest.cs +++ b/test/Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests/RowNumberPagingTest.cs @@ -30,12 +30,12 @@ public override void Skip() Assert.Equal( @"@__p_0: 5 -SELECT [t0].[CustomerID], [t0].[Address], [t0].[City], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Country], [t0].[Fax], [t0].[Phone], [t0].[PostalCode], [t0].[Region] +SELECT [t].[CustomerID], [t].[Address], [t].[City], [t].[CompanyName], [t].[ContactName], [t].[ContactTitle], [t].[Country], [t].[Fax], [t].[Phone], [t].[PostalCode], [t].[Region] FROM ( SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], ROW_NUMBER() OVER(ORDER BY [c].[CustomerID]) AS [__RowNumber__] FROM [Customers] AS [c] -) AS [t0] -WHERE [t0].[__RowNumber__] > @__p_0", +) AS [t] +WHERE [t].[__RowNumber__] > @__p_0", Sql); } @@ -46,12 +46,12 @@ public override void Skip_no_orderby() Assert.EndsWith( @"@__p_0: 5 -SELECT [t0].[CustomerID], [t0].[Address], [t0].[City], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Country], [t0].[Fax], [t0].[Phone], [t0].[PostalCode], [t0].[Region] +SELECT [t].[CustomerID], [t].[Address], [t].[City], [t].[CompanyName], [t].[ContactName], [t].[ContactTitle], [t].[Country], [t].[Fax], [t].[Phone], [t].[PostalCode], [t].[Region] FROM ( SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], ROW_NUMBER() OVER(ORDER BY @@RowCount) AS [__RowNumber__] FROM [Customers] AS [c] -) AS [t0] -WHERE [t0].[__RowNumber__] > @__p_0", +) AS [t] +WHERE [t].[__RowNumber__] > @__p_0", Sql); } @@ -63,12 +63,12 @@ public override void Skip_Take() @"@__p_0: 5 @__p_1: 10 -SELECT [t0].[CustomerID], [t0].[Address], [t0].[City], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Country], [t0].[Fax], [t0].[Phone], [t0].[PostalCode], [t0].[Region] +SELECT [t].[CustomerID], [t].[Address], [t].[City], [t].[CompanyName], [t].[ContactName], [t].[ContactTitle], [t].[Country], [t].[Fax], [t].[Phone], [t].[PostalCode], [t].[Region] FROM ( SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], ROW_NUMBER() OVER(ORDER BY [c].[ContactName]) AS [__RowNumber__] FROM [Customers] AS [c] -) AS [t0] -WHERE ([t0].[__RowNumber__] > @__p_0) AND ([t0].[__RowNumber__] <= (@__p_0 + @__p_1))", +) AS [t] +WHERE ([t].[__RowNumber__] > @__p_0) AND ([t].[__RowNumber__] <= (@__p_0 + @__p_1))", Sql); } @@ -80,13 +80,13 @@ public override void Join_Customers_Orders_Skip_Take() @"@__p_0: 10 @__p_1: 5 -SELECT [t0].[ContactName], [t0].[OrderID] +SELECT [t].[ContactName], [t].[OrderID] FROM ( SELECT [c].[ContactName], [o].[OrderID], ROW_NUMBER() OVER(ORDER BY [o].[OrderID]) AS [__RowNumber__] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] -) AS [t0] -WHERE ([t0].[__RowNumber__] > @__p_0) AND ([t0].[__RowNumber__] <= (@__p_0 + @__p_1))", +) AS [t] +WHERE ([t].[__RowNumber__] > @__p_0) AND ([t].[__RowNumber__] <= (@__p_0 + @__p_1))", Sql); } @@ -98,13 +98,13 @@ public override void Join_Customers_Orders_Projection_With_String_Concat_Skip_Ta @"@__p_0: 10 @__p_1: 5 -SELECT [t0].[c0], [t0].[OrderID] +SELECT [t].[c0], [t].[OrderID] FROM ( SELECT ([c].[ContactName] + ' ') + [c].[ContactTitle] AS [c0], [o].[OrderID], ROW_NUMBER() OVER(ORDER BY [o].[OrderID]) AS [__RowNumber__] FROM [Customers] AS [c] INNER JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] -) AS [t0] -WHERE ([t0].[__RowNumber__] > @__p_0) AND ([t0].[__RowNumber__] <= (@__p_0 + @__p_1))", +) AS [t] +WHERE ([t].[__RowNumber__] > @__p_0) AND ([t].[__RowNumber__] <= (@__p_0 + @__p_1))", Sql); } @@ -115,16 +115,16 @@ public override void Take_Skip() Assert.Equal(@"@__p_0: 10 @__p_1: 5 -SELECT [t1].* +SELECT [t0].* FROM ( - SELECT [t0].*, ROW_NUMBER() OVER(ORDER BY [t0].[ContactName]) AS [__RowNumber__] + SELECT [t].*, ROW_NUMBER() OVER(ORDER BY [t].[ContactName]) AS [__RowNumber__] FROM ( SELECT TOP(@__p_0) [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] ORDER BY [c].[ContactName] - ) AS [t0] -) AS [t1] -WHERE [t1].[__RowNumber__] > @__p_1", + ) AS [t] +) AS [t0] +WHERE [t0].[__RowNumber__] > @__p_1", Sql); } @@ -136,19 +136,19 @@ public override void Take_Skip_Distinct() @"@__p_0: 10 @__p_1: 5 -SELECT DISTINCT [t1].* +SELECT DISTINCT [t0].* FROM ( - SELECT [t2].* + SELECT [t1].* FROM ( - SELECT [t0].*, ROW_NUMBER() OVER(ORDER BY [t0].[ContactName]) AS [__RowNumber__] + SELECT [t].*, ROW_NUMBER() OVER(ORDER BY [t].[ContactName]) AS [__RowNumber__] FROM ( SELECT TOP(@__p_0) [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] ORDER BY [c].[ContactName] - ) AS [t0] - ) AS [t2] - WHERE [t2].[__RowNumber__] > @__p_1 -) AS [t1]", + ) AS [t] + ) AS [t1] + WHERE [t1].[__RowNumber__] > @__p_1 +) AS [t0]", Sql); } @@ -159,19 +159,19 @@ public override void Take_skip_null_coalesce_operator() Assert.Equal(@"@__p_0: 10 @__p_1: 5 -SELECT DISTINCT [t1].* +SELECT DISTINCT [t0].* FROM ( - SELECT [t2].* + SELECT [t1].* FROM ( - SELECT [t0].*, ROW_NUMBER() OVER(ORDER BY COALESCE([t0].[Region], 'ZZ')) AS [__RowNumber__] + SELECT [t].*, ROW_NUMBER() OVER(ORDER BY COALESCE([t].[Region], 'ZZ')) AS [__RowNumber__] FROM ( SELECT TOP(@__p_0) [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] ORDER BY COALESCE([c].[Region], 'ZZ') - ) AS [t0] - ) AS [t2] - WHERE [t2].[__RowNumber__] > @__p_1 -) AS [t1]", + ) AS [t] + ) AS [t1] + WHERE [t1].[__RowNumber__] > @__p_1 +) AS [t0]", Sql); } @@ -182,16 +182,16 @@ public override void Select_take_skip_null_coalesce_operator() Assert.Equal(@"@__p_0: 10 @__p_1: 5 -SELECT [t1].* +SELECT [t0].* FROM ( - SELECT [t0].*, ROW_NUMBER() OVER(ORDER BY [Coalesce]) AS [__RowNumber__] + SELECT [t].*, ROW_NUMBER() OVER(ORDER BY [Coalesce]) AS [__RowNumber__] FROM ( SELECT TOP(@__p_0) [c].[CustomerID], [c].[CompanyName], COALESCE([c].[Region], 'ZZ') AS [Coalesce] FROM [Customers] AS [c] ORDER BY [Coalesce] - ) AS [t0] -) AS [t1] -WHERE [t1].[__RowNumber__] > @__p_1", + ) AS [t] +) AS [t0] +WHERE [t0].[__RowNumber__] > @__p_1", Sql); }