diff --git a/src/EFCore.Relational/Query/EntityProjectionExpression.cs b/src/EFCore.Relational/Query/EntityProjectionExpression.cs index bab17066aae..fb95ea0f1eb 100644 --- a/src/EFCore.Relational/Query/EntityProjectionExpression.cs +++ b/src/EFCore.Relational/Query/EntityProjectionExpression.cs @@ -123,7 +123,7 @@ public virtual EntityProjectionExpression UpdateEntityType(IEntityType derivedTy var discriminatorExpression = DiscriminatorExpression; if (DiscriminatorExpression is CaseExpression caseExpression) { - var entityTypesToSelect = derivedType.GetConcreteDerivedTypesInclusive().Select(e => e.GetDiscriminatorValue()).ToList(); + var entityTypesToSelect = derivedType.GetConcreteDerivedTypesInclusive().Select(e => (string)e.GetDiscriminatorValue()!).ToList(); var whenClauses = caseExpression.WhenClauses .Where(wc => entityTypesToSelect.Contains((string)((SqlConstantExpression)wc.Result).Value!)) .ToList(); diff --git a/src/EFCore.Relational/Query/Internal/TpcTablesExpression.cs b/src/EFCore.Relational/Query/Internal/TpcTablesExpression.cs deleted file mode 100644 index 60a0ba7e16e..00000000000 --- a/src/EFCore.Relational/Query/Internal/TpcTablesExpression.cs +++ /dev/null @@ -1,150 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Diagnostics.CodeAnalysis; -using Microsoft.EntityFrameworkCore.Query.SqlExpressions; - -namespace Microsoft.EntityFrameworkCore.Query.Internal; - -/// -/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to -/// the same compatibility standards as public APIs. It may be changed or removed without notice in -/// any release. You should only use it directly in your code with extreme caution and knowing that -/// doing so can result in application failures when updating to a new Entity Framework Core release. -/// -public class TpcTablesExpression : TableExpressionBase -{ - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public TpcTablesExpression( - string? alias, IEntityType entityType, IReadOnlyList subSelectExpressions) - : base(alias) - { - EntityType = entityType; - SelectExpressions = subSelectExpressions; - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - private TpcTablesExpression( - string? alias, - IEntityType entityType, - IReadOnlyList subSelectExpressions, - IEnumerable? annotations) - : base(alias, annotations) - { - EntityType = entityType; - SelectExpressions = subSelectExpressions; - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - [NotNull] - public override string? Alias - { - get => base.Alias!; - internal set => base.Alias = value; - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual IEntityType EntityType { get; } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual IReadOnlyList SelectExpressions { get; } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - public virtual TpcTablesExpression Prune(IReadOnlyList discriminatorValues, IReadOnlyCollection? referencedColumns) - { - var subSelectExpressions = discriminatorValues.Count == 0 - ? new List { SelectExpressions[0] } - : SelectExpressions.Where(se => - discriminatorValues.Contains((string)((SqlConstantExpression)se.Projection[^1].Expression).Value!)).ToList(); - - Check.DebugAssert(subSelectExpressions.Count > 0, "TPC must have at least 1 table selected."); - - if (referencedColumns != null) - { - foreach (var se in subSelectExpressions) - { - se.Prune(referencedColumns); - } - } - - return new TpcTablesExpression(Alias, EntityType, subSelectExpressions, GetAnnotations()); - } - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - // This is implementation detail hence visitors are not supposed to see inside unless they really need to. - protected override Expression VisitChildren(ExpressionVisitor visitor) => this; - - /// - /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to - /// the same compatibility standards as public APIs. It may be changed or removed without notice in - /// any release. You should only use it directly in your code with extreme caution and knowing that - /// doing so can result in application failures when updating to a new Entity Framework Core release. - /// - protected override void Print(ExpressionPrinter expressionPrinter) - { - expressionPrinter.AppendLine("("); - using (expressionPrinter.Indent()) - { - expressionPrinter.VisitCollection(SelectExpressions, e => e.AppendLine().AppendLine("UNION ALL")); - } - expressionPrinter.AppendLine() - .AppendLine(") AS " + Alias); - PrintAnnotations(expressionPrinter); - } - - /// - public override bool Equals(object? obj) - => obj != null - && (ReferenceEquals(this, obj) - || obj is TpcTablesExpression tpcTablesExpression - && Equals(tpcTablesExpression)); - - private bool Equals(TpcTablesExpression tpcTablesExpression) - { - if (!base.Equals(tpcTablesExpression) - || EntityType != tpcTablesExpression.EntityType) - { - return false; - } - - return SelectExpressions.SequenceEqual(tpcTablesExpression.SelectExpressions); - } - - /// - public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), EntityType); -} diff --git a/src/EFCore.Relational/Query/QuerySqlGenerator.cs b/src/EFCore.Relational/Query/QuerySqlGenerator.cs index 626b2e8e15e..ad8c1672c06 100644 --- a/src/EFCore.Relational/Query/QuerySqlGenerator.cs +++ b/src/EFCore.Relational/Query/QuerySqlGenerator.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.EntityFrameworkCore.Query.Internal; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage.Internal; @@ -148,141 +147,77 @@ private static bool IsNonComposedSetOperation(SelectExpression selectExpression) column.Name, setOperation.Source1.Projection[index].Alias, StringComparison.Ordinal)) .All(e => e); - private static bool IsNonComposedTpc(SelectExpression selectExpression) - => selectExpression.Offset == null - && selectExpression.Limit == null - && !selectExpression.IsDistinct - && selectExpression.Predicate == null - && selectExpression.Having == null - && selectExpression.Orderings.Count == 0 - && selectExpression.GroupBy.Count == 0 - && selectExpression.Tables.Count == 1 - && selectExpression.Tables[0] is TpcTablesExpression tpcTablesExpression - && selectExpression.Projection.Count == tpcTablesExpression.SelectExpressions[0].Projection.Count - && selectExpression.Projection.Select( - (pe, index) => pe.Expression is ColumnExpression column - && string.Equals(column.TableAlias, tpcTablesExpression.Alias, StringComparison.Ordinal) - && string.Equals( - column.Name, tpcTablesExpression.SelectExpressions[0].Projection[index].Alias, StringComparison.Ordinal)) - .All(e => e); - /// - protected override Expression VisitExtension(Expression extensionExpression) + protected override Expression VisitSelect(SelectExpression selectExpression) { - if (extensionExpression is TpcTablesExpression tpcTablesExpression) + IDisposable? subQueryIndent = null; + if (selectExpression.Alias != null) { _relationalCommandBuilder.AppendLine("("); - using (_relationalCommandBuilder.Indent()) - { - GenerateList(tpcTablesExpression.SelectExpressions, e => Visit(e), e => e.AppendLine().AppendLine("UNION ALL")); - } - _relationalCommandBuilder.AppendLine() - .Append(")") - .Append(AliasSeparator) - .Append(_sqlGenerationHelper.DelimitIdentifier(tpcTablesExpression.Alias)); - - return tpcTablesExpression; + subQueryIndent = _relationalCommandBuilder.Indent(); } - return base.VisitExtension(extensionExpression); - } - - /// - protected override Expression VisitSelect(SelectExpression selectExpression) - { if (IsNonComposedSetOperation(selectExpression)) { // Naked set operation GenerateSetOperation((SetOperationBase)selectExpression.Tables[0]); - - return selectExpression; } - - IDisposable? subQueryIndent = null; - - if (IsNonComposedTpc(selectExpression)) + else { - var tpcTablesExpression = (TpcTablesExpression)selectExpression.Tables[0]; - if (selectExpression.Alias != null) + _relationalCommandBuilder.Append("SELECT "); + + if (selectExpression.IsDistinct) { - _relationalCommandBuilder.AppendLine("("); - subQueryIndent = _relationalCommandBuilder.Indent(); + _relationalCommandBuilder.Append("DISTINCT "); } - GenerateList(tpcTablesExpression.SelectExpressions, e => Visit(e), e => e.AppendLine().AppendLine("UNION ALL")); + GenerateTop(selectExpression); - if (selectExpression.Alias != null) + if (selectExpression.Projection.Any()) { - subQueryIndent!.Dispose(); - - _relationalCommandBuilder.AppendLine() - .Append(")") - .Append(AliasSeparator) - .Append(_sqlGenerationHelper.DelimitIdentifier(selectExpression.Alias)); + GenerateList(selectExpression.Projection, e => Visit(e)); + } + else + { + _relationalCommandBuilder.Append("1"); } - return selectExpression; - } - - if (selectExpression.Alias != null) - { - _relationalCommandBuilder.AppendLine("("); - subQueryIndent = _relationalCommandBuilder.Indent(); - } - - _relationalCommandBuilder.Append("SELECT "); - - if (selectExpression.IsDistinct) - { - _relationalCommandBuilder.Append("DISTINCT "); - } - - GenerateTop(selectExpression); - - if (selectExpression.Projection.Any()) - { - GenerateList(selectExpression.Projection, e => Visit(e)); - } - else - { - _relationalCommandBuilder.Append("1"); - } + if (selectExpression.Tables.Any()) + { + _relationalCommandBuilder.AppendLine().Append("FROM "); - if (selectExpression.Tables.Any()) - { - _relationalCommandBuilder.AppendLine().Append("FROM "); + GenerateList(selectExpression.Tables, e => Visit(e), sql => sql.AppendLine()); + } + else + { + GeneratePseudoFromClause(); + } - GenerateList(selectExpression.Tables, e => Visit(e), sql => sql.AppendLine()); - } - else - { - GeneratePseudoFromClause(); - } + if (selectExpression.Predicate != null) + { + _relationalCommandBuilder.AppendLine().Append("WHERE "); - if (selectExpression.Predicate != null) - { - _relationalCommandBuilder.AppendLine().Append("WHERE "); + Visit(selectExpression.Predicate); + } - Visit(selectExpression.Predicate); - } + if (selectExpression.GroupBy.Count > 0) + { + _relationalCommandBuilder.AppendLine().Append("GROUP BY "); - if (selectExpression.GroupBy.Count > 0) - { - _relationalCommandBuilder.AppendLine().Append("GROUP BY "); + GenerateList(selectExpression.GroupBy, e => Visit(e)); + } - GenerateList(selectExpression.GroupBy, e => Visit(e)); - } + if (selectExpression.Having != null) + { + _relationalCommandBuilder.AppendLine().Append("HAVING "); - if (selectExpression.Having != null) - { - _relationalCommandBuilder.AppendLine().Append("HAVING "); + Visit(selectExpression.Having); + } - Visit(selectExpression.Having); + GenerateOrderings(selectExpression); + GenerateLimitOffset(selectExpression); } - GenerateOrderings(selectExpression); - GenerateLimitOffset(selectExpression); - if (selectExpression.Alias != null) { subQueryIndent!.Dispose(); diff --git a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs index a51f668a9ee..49db4d98674 100644 --- a/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryTranslationPostprocessor.cs @@ -39,6 +39,7 @@ public override Expression Process(Expression query) query = base.Process(query); query = new SelectExpressionProjectionApplyingExpressionVisitor( ((RelationalQueryCompilationContext)QueryCompilationContext).QuerySplittingBehavior).Visit(query); + query = new SelectExpressionPruningExpressionVisitor().Visit(query); #if DEBUG // Verifies that all SelectExpression are marked as immutable after this point. @@ -47,7 +48,7 @@ public override Expression Process(Expression query) // Which points to possible mutation of a SelectExpression being used in multiple places. new TableAliasVerifyingExpressionVisitor().Visit(query); #endif - query = new SelectExpressionPruningExpressionVisitor().Visit(query); + query = new SqlExpressionSimplifyingExpressionVisitor(RelationalDependencies.SqlExpressionFactory, _useRelationalNulls) .Visit(query); query = new RelationalValueConverterCompensatingExpressionVisitor(RelationalDependencies.SqlExpressionFactory).Visit(query); @@ -76,16 +77,6 @@ private sealed class SelectExpressionMutableVerifyingExpressionVisitor : Express return shapedQueryExpression; } - if (expression is TpcTablesExpression tpcTablesExpression) - { - foreach (var se in tpcTablesExpression.SelectExpressions) - { - Visit(se); - } - - return expression; - } - return base.Visit(expression); } } @@ -129,6 +120,14 @@ public Expression EntryPoint(Expression expression) _usedAliases.Clear(); _visitedTableExpressionBases.Clear(); + if (expression is SelectExpression selectExpression) + { + foreach (var alias in selectExpression.RemovedAliases()) + { + _usedAliases.Add(alias); + } + } + var result = Visit(expression); foreach (var group in _usedAliases.GroupBy(e => e[..1])) @@ -152,15 +151,6 @@ public Expression EntryPoint(Expression expression) public override Expression? Visit(Expression? expression) { var visitedExpression = base.Visit(expression); - if (visitedExpression is TpcTablesExpression tpcTablesExpression) - { - // We need to look inside SelectExpressions in TPC for aliases - foreach (var selectExpression in tpcTablesExpression.SelectExpressions) - { - Visit(selectExpression); - } - } - if (visitedExpression is TableExpressionBase tableExpressionBase && !_visitedTableExpressionBases.Contains(tableExpressionBase) && tableExpressionBase.Alias != null) diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index 4db87cba93a..a31edeb424e 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -1128,7 +1128,8 @@ protected override Expression VisitTypeBinary(TypeBinaryExpression typeBinaryExp } // TPT or TPC - var discriminatorValues = derivedType.GetConcreteDerivedTypesInclusive().Select(e => e.GetDiscriminatorValue()).ToList(); + var discriminatorValues = derivedType.GetConcreteDerivedTypesInclusive() + .Select(e => (string)e.GetDiscriminatorValue()!).ToList(); if (entityReferenceExpression.SubqueryEntity != null) { var entityShaper = (EntityShaperExpression)entityReferenceExpression.SubqueryEntity.ShaperExpression; diff --git a/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs index 07722ce62df..2adea6ad757 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ExistsExpression.cs @@ -28,7 +28,7 @@ public ExistsExpression( { #if DEBUG - if (subquery.IsMutable() == true) + if (subquery.IsMutable()) { throw new InvalidOperationException(); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs index 32fd0c4d6bd..9f639a10520 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/ScalarSubqueryExpression.cs @@ -32,7 +32,7 @@ private static SelectExpression Verify(SelectExpression selectExpression) } #if DEBUG - if (selectExpression.IsMutable() == true) + if (selectExpression.IsMutable()) { throw new InvalidOperationException(); } diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs index 5a4c5529dec..5fbd0025c3e 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs @@ -405,17 +405,6 @@ public AliasUniquifier(HashSet usedAliases) _visitedSelectExpressions.Add(innerSelectExpression); } - if (expression is TpcTablesExpression tpcTablesExpression) - { - // We uniquify aliases in inner selectexpressions too - foreach (var selectExpression in tpcTablesExpression.SelectExpressions) - { - Visit(selectExpression); - } - - return expression; - } - return base.Visit(expression); } } @@ -477,6 +466,87 @@ public override int GetHashCode() => 0; } + private sealed class TpcTablesExpression : TableExpressionBase + { + public TpcTablesExpression( + string? alias, IEntityType entityType, IReadOnlyList subSelectExpressions) + : base(alias) + { + EntityType = entityType; + SelectExpressions = subSelectExpressions; + } + + private TpcTablesExpression( + string? alias, + IEntityType entityType, + IReadOnlyList subSelectExpressions, + IEnumerable? annotations) + : base(alias, annotations) + { + EntityType = entityType; + SelectExpressions = subSelectExpressions; + } + + [NotNull] + public override string? Alias + { + get => base.Alias!; + internal set => base.Alias = value; + } + + public IEntityType EntityType { get; } + + public IReadOnlyList SelectExpressions { get; } + + public TpcTablesExpression Prune(IReadOnlyList discriminatorValues) + { + var subSelectExpressions = discriminatorValues.Count == 0 + ? new List { SelectExpressions[0] } + : SelectExpressions.Where(se => + discriminatorValues.Contains((string)((SqlConstantExpression)se.Projection[^1].Expression).Value!)).ToList(); + + Check.DebugAssert(subSelectExpressions.Count > 0, "TPC must have at least 1 table selected."); + + return new TpcTablesExpression(Alias, EntityType, subSelectExpressions, GetAnnotations()); + } + + // This is implementation detail hence visitors are not supposed to see inside unless they really need to. + protected override Expression VisitChildren(ExpressionVisitor visitor) => this; + + protected override void Print(ExpressionPrinter expressionPrinter) + { + expressionPrinter.AppendLine("("); + using (expressionPrinter.Indent()) + { + expressionPrinter.VisitCollection(SelectExpressions, e => e.AppendLine().AppendLine("UNION ALL")); + } + expressionPrinter.AppendLine() + .AppendLine(") AS " + Alias); + PrintAnnotations(expressionPrinter); + } + + /// + public override bool Equals(object? obj) + => obj != null + && (ReferenceEquals(this, obj) + || obj is TpcTablesExpression tpcTablesExpression + && Equals(tpcTablesExpression)); + + private bool Equals(TpcTablesExpression tpcTablesExpression) + { + if (!base.Equals(tpcTablesExpression) + || EntityType != tpcTablesExpression.EntityType) + { + return false; + } + + return SelectExpressions.SequenceEqual(tpcTablesExpression.SelectExpressions); + } + + /// + public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), EntityType); + } + private sealed class ConcreteColumnExpression : ColumnExpression { private readonly TableReferenceExpression _table; @@ -824,7 +894,7 @@ private sealed class CloningExpressionVisitor : ExpressionVisitor var newProjections = selectExpression._projection.Select(Visit).ToList(); var newTables = selectExpression._tables.Select(Visit).ToList(); - var tpcTableMap = selectExpression._tables.Zip(newTables) + var tpcTablesMap = selectExpression._tables.Select(UnwrapJoinExpression).Zip(newTables.Select(UnwrapJoinExpression)) .Where(e => e.First is TpcTablesExpression) .ToDictionary(e => (TpcTablesExpression)e.First, e => (TpcTablesExpression)e.Second); @@ -861,10 +931,12 @@ private sealed class CloningExpressionVisitor : ExpressionVisitor newSelectExpression._mutable = selectExpression._mutable; newSelectExpression._tptLeftJoinTables.AddRange(selectExpression._tptLeftJoinTables); + foreach (var kvp in selectExpression._tpcDiscriminatorValues) { - newSelectExpression._tpcDiscriminatorValues[tpcTableMap[kvp.Key]] = kvp.Value; + newSelectExpression._tpcDiscriminatorValues[tpcTablesMap[kvp.Key]] = kvp.Value; } + // Since identifiers are ColumnExpression, they are not visited since they don't contain SelectExpression inside it. newSelectExpression._identifier.AddRange(selectExpression._identifier); newSelectExpression._childIdentifiers.AddRange(selectExpression._childIdentifiers); @@ -924,4 +996,158 @@ public ColumnExpressionReplacingExpressionVisitor( concreteColumnExpression.IsNullable) : base.Visit(expression); } + + private sealed class TpcTableExpressionRemovingExpressionVisitor : ExpressionVisitor + { + private readonly HashSet _usedAliases; + + public TpcTableExpressionRemovingExpressionVisitor(HashSet usedAliases) + { + _usedAliases = usedAliases; + } + + [return: NotNullIfNotNull("expression")] + public override Expression? Visit(Expression? expression) + { + if (expression is SelectExpression selectExpression + && selectExpression._tpcDiscriminatorValues.Count > 0) + { + // If selectExpression doesn't have any other component and only TPC tables then we can lift it + // We ignore projection here because if this selectExpression has projection from inner TPC + // Then TPC will have superset of projection + var identitySelect = selectExpression.Offset == null + && selectExpression.Limit == null + && !selectExpression.IsDistinct + && selectExpression.Predicate == null + && selectExpression.Having == null + && selectExpression.Orderings.Count == 0 + && selectExpression.GroupBy.Count == 0 + && selectExpression.Tables.Count == 1 + // Any non-column projection means some composition which cannot be removed + && selectExpression.Projection.All(e => e.Expression is ColumnExpression); + + foreach (var kvp in selectExpression._tpcDiscriminatorValues) + { + var tpcTablesExpression = kvp.Key; + var subSelectExpressions = tpcTablesExpression.Prune(kvp.Value.Item2).SelectExpressions + .Select(e => AssignUniqueAliasToTable(e)).ToList(); + var firstSelectExpression = subSelectExpressions[0]; // There will be at least one. + + int[]? reindexingMap = null; + if (identitySelect && selectExpression.Alias == null) + { + // Alias would be null when it is Exists/In like query or top level + // In Exists like query there is no projection + // In InExpression with subquery there will be only 1 projection + // In top-level the ordering of projection matters for shaper + // So for all cases in case of identity select when we are doing the lift, we need to remap projections + reindexingMap = new int[selectExpression.Projection.Count]; + var innerProjections = firstSelectExpression.Projection.Select(e => e.Alias).ToList(); + var identityMap = true; + for (var i = 0; i < selectExpression.Projection.Count; i++) + { + var newIndex = innerProjections.FindIndex( + e => string.Equals(e, selectExpression.Projection[i].Alias, StringComparison.Ordinal)); + if (newIndex == -1) + { + // If for whatever reason outer has additional projection which cannot be remapped we avoid lift + identitySelect = false; + reindexingMap = null; + break; + } + + identityMap &= (i == newIndex); + reindexingMap[i] = newIndex; + } + + if (identityMap) + { + // If projection is same on outer/inner we don't need remapping + reindexingMap = null; + } + } + + if (identitySelect) + { + // If we are lifting then we remove the alias for tpc because it will be unused. + _usedAliases.Remove(tpcTablesExpression.Alias); + } + + RemapProjections(reindexingMap, firstSelectExpression); + var result = subSelectExpressions[0]; + for (var i = 1; i < subSelectExpressions.Count; i++) + { + var setOperationAlias = GenerateUniqueAlias(_usedAliases, "t"); + var source1 = result; + var source2 = subSelectExpressions[i]; + RemapProjections(reindexingMap, source2); + var generatedSelectExpression = new SelectExpression(alias: null); + + var unionExpression = new UnionExpression(setOperationAlias, source1, source2, distinct: false); + var tableReferenceExpression = new TableReferenceExpression(generatedSelectExpression, setOperationAlias); + generatedSelectExpression._tables.Add(unionExpression); + generatedSelectExpression._tableReferences.Add(tableReferenceExpression); + foreach (var projection in result.Projection) + { + generatedSelectExpression._projection.Add( + new ProjectionExpression(new ConcreteColumnExpression(projection, tableReferenceExpression), projection.Alias)); + } + generatedSelectExpression._mutable = false; + result = generatedSelectExpression; + } + + if (identitySelect) + { + result.Alias = selectExpression.Alias; + if (selectExpression.Alias == null) + { + // If top-level them copy over bindings for shaper + result._projectionMapping = selectExpression._projectionMapping; + result._clientProjections = selectExpression._clientProjections; + } + + // Since identity select implies only 1 table so we can return without worrying about another iteration. + // Identity select shouldn't require base visit. + return result; + } + else + { + result.Alias = tpcTablesExpression.Alias; + var tableIndex = selectExpression._tables.FindIndex(teb => ReferenceEquals(UnwrapJoinExpression(teb), tpcTablesExpression)); + var table = selectExpression._tables[tableIndex]; + selectExpression._tables[tableIndex] = (TableExpressionBase)ReplacingExpressionVisitor.Replace( + tpcTablesExpression, result, table); + } + + SelectExpression AssignUniqueAliasToTable(SelectExpression se) + { + // we assign unique alias to inner tables here so that we can avoid wasting aliases on pruned tables + var table = se._tables[0]; + var alias = GenerateUniqueAlias(_usedAliases, table.Alias!); + table.Alias = alias; + se._tableReferences[0].Alias = alias; + + return se; + } + } + + selectExpression._tpcDiscriminatorValues.Clear(); + } + + return base.Visit(expression); + } + + private void RemapProjections(int[]? map, SelectExpression selectExpression) + { + if (map != null) + { + var projections = selectExpression.Projection.ToList(); + selectExpression._projection.Clear(); + for (var i = 0; i < map.Length; i++) + { + selectExpression._projection.Add(projections[map[i]]); + } + } + } + } } diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 06d036d5585..7405cbae7ba 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -56,6 +56,10 @@ public sealed partial class SelectExpression : TableExpressionBase private readonly List _aliasForClientProjections = new(); private CloningExpressionVisitor? _cloningExpressionVisitor; +#if DEBUG + private List? _removedAliases; +#endif + private SelectExpression( string? alias, List projections, @@ -260,15 +264,14 @@ internal SelectExpression(IEntityType entityType, ISqlExpressionFactory sqlExpre } var subSelectExpressions = new List(); - var tableAlias = GenerateUniqueAlias(_usedAliases, "t"); var discriminatorValues = new List(); for (var i = 0; i < entityTypes.Length; i++) { var et = entityTypes[i]; var table = tables[i]; var selectExpression = new SelectExpression(alias: null); + // We intentionally do not assign unique aliases here in case some select expression gets pruned later var tableExpression = new TableExpression(table); - tableExpression.Alias = GenerateUniqueAlias(_usedAliases, tableExpression.Alias); var tableReferenceExpression = new TableReferenceExpression(selectExpression, tableExpression.Alias); selectExpression._tables.Add(tableExpression); selectExpression._tableReferences.Add(tableReferenceExpression); @@ -291,6 +294,8 @@ internal SelectExpression(IEntityType entityType, ISqlExpressionFactory sqlExpre selectExpression._mutable = false; } + // We only assign unique alias to Tpc + var tableAlias = GenerateUniqueAlias(_usedAliases, "t"); var tpcTables = new TpcTablesExpression(tableAlias, entityType, subSelectExpressions); var tpcTableReference = new TableReferenceExpression(this, tableAlias); _tables.Add(tpcTables); @@ -1331,6 +1336,7 @@ public void ApplyPredicate(SqlExpression sqlExpression) || sqlExpression is InExpression { Subquery: null, IsNegated: false }) && _groupBy.Count == 0) { + // If the intersection is empty then we don't remove predicate so that the filter empty out all results. if (sqlExpression is SqlBinaryExpression sqlBinaryExpression) { @@ -1369,7 +1375,7 @@ public void ApplyPredicate(SqlExpression sqlExpression) && _tpcDiscriminatorValues.TryGetValue(itemTpc, out var itemTuple) && itemTuple.Item1.Equals(itemColumn) && inExpression.Values is SqlConstantExpression itemConstant - && itemConstant.Value is string[] values) + && itemConstant.Value is List values) { var newList = itemTuple.Item2.Intersect(values).ToList(); if (newList.Count > 0) @@ -1718,6 +1724,7 @@ private void ApplySetOperation(SetOperationType setOperationType, SelectExpressi select1._identifier.AddRange(_identifier); _identifier.Clear(); select1._tptLeftJoinTables.AddRange(_tptLeftJoinTables); + _tptLeftJoinTables.Clear(); foreach (var kvp in _tpcDiscriminatorValues) { select1._tpcDiscriminatorValues[kvp.Key] = kvp.Value; @@ -2423,13 +2430,17 @@ private void AddJoin( || innerSelectExpression.IsDistinct || innerSelectExpression.Predicate != null || innerSelectExpression.Tables.Count > 1 - || innerSelectExpression.GroupBy.Count > 0 - || innerSelectExpression._tpcDiscriminatorValues.Count > 0) + || innerSelectExpression.GroupBy.Count > 0) { joinPredicate = innerSelectExpression.PushdownIntoSubqueryInternal().Remap(joinPredicate); innerPushdownOccurred = true; } + foreach (var kvp in innerSelectExpression._tpcDiscriminatorValues) + { + _tpcDiscriminatorValues[kvp.Key] = kvp.Value; + } + if (_identifier.Count > 0 && innerSelectExpression._identifier.Count > 0) { @@ -2902,12 +2913,12 @@ private SqlRemappingVisitor PushdownIntoSubqueryInternal() Offset = null; Limit = null; subquery._tptLeftJoinTables.AddRange(_tptLeftJoinTables); + _tptLeftJoinTables.Clear(); foreach (var kvp in _tpcDiscriminatorValues) { - subquery._tpcDiscriminatorValues.Add(kvp.Key, kvp.Value); + subquery._tpcDiscriminatorValues[kvp.Key] = kvp.Value; } _tpcDiscriminatorValues.Clear(); - _tptLeftJoinTables.Clear(); var subqueryTableReferenceExpression = new TableReferenceExpression(this, subquery.Alias!); // Do NOT use AddTable here. The subquery already have unique aliases we don't need to traverse it again to make it unique. @@ -3177,9 +3188,22 @@ public SelectExpression Clone() /// [EntityFrameworkInternal] public SelectExpression Prune() - => Prune(referencedColumns: null); + { + var selectExpression = (SelectExpression)new TpcTableExpressionRemovingExpressionVisitor(_usedAliases).Visit(this); +#if DEBUG + selectExpression._removedAliases = new(); + selectExpression = selectExpression.Prune(referencedColumns: null, selectExpression._removedAliases); +#else + selectExpression = selectExpression.Prune(referencedColumns: null); +#endif + return selectExpression; + } - internal SelectExpression Prune(IReadOnlyCollection? referencedColumns = null) +#if DEBUG + private SelectExpression Prune(IReadOnlyCollection? referencedColumns, List removedAliases) +#else + private SelectExpression Prune(IReadOnlyCollection? referencedColumns) +#endif { if (referencedColumns != null && !IsDistinct) @@ -3211,18 +3235,29 @@ internal SelectExpression Prune(IReadOnlyCollection? referencedColumns = _tableReferences.RemoveAt(i); removedTableCount++; i--; - +#if DEBUG + removedAliases.Add(tableAlias); +#endif continue; } - if (table is TpcTablesExpression tpcTablesExpression) - { - _tables[i] = tpcTablesExpression.Prune(_tpcDiscriminatorValues[tpcTablesExpression].Item2, columnsMap[tableAlias]); - } - if (UnwrapJoinExpression(table) is SelectExpression innerSelectExpression) { +#if DEBUG + innerSelectExpression.Prune(columnsMap[tableAlias], removedAliases); +#else innerSelectExpression.Prune(columnsMap[tableAlias]); +#endif + } + else if (table is SetOperationBase { IsDistinct: false } setOperation) + { +#if DEBUG + setOperation.Source1.Prune(columnsMap[tableAlias], removedAliases); + setOperation.Source2.Prune(columnsMap[tableAlias], removedAliases); +#else + setOperation.Source1.Prune(columnsMap[tableAlias]); + setOperation.Source2.Prune(columnsMap[tableAlias]); +#endif } } @@ -3451,6 +3486,10 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) .ToList(); _childIdentifiers.Clear(); _childIdentifiers.AddRange(childIdentifier); + foreach (var kvp in _tpcDiscriminatorValues) + { + _tpcDiscriminatorValues[kvp.Key] = ((ColumnExpression)visitor.Visit(kvp.Value.Item1), kvp.Value.Item2); + } return this; } @@ -3523,6 +3562,13 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) var childIdentifier = VisitList( _childIdentifiers.Select(e => e.Column).ToList(), inPlace: false, out var childIdentifierChanged); changed |= childIdentifierChanged; + var newTpcDiscriminatorValues = new Dictionary)>(); + foreach (var kvp in _tpcDiscriminatorValues) + { + var newDiscriminatorColumnForTpc = (ColumnExpression)visitor.Visit(kvp.Value.Item1); + changed |= newDiscriminatorColumnForTpc != kvp.Value.Item1; + newTpcDiscriminatorValues[kvp.Key] = (newDiscriminatorColumnForTpc, kvp.Value.Item2); + } if (changed) { @@ -3542,11 +3588,10 @@ protected override Expression VisitChildren(ExpressionVisitor visitor) }; newSelectExpression._mutable = false; newSelectExpression._tptLeftJoinTables.AddRange(_tptLeftJoinTables); - foreach (var kvp in _tpcDiscriminatorValues) + foreach (var kvp in newTpcDiscriminatorValues) { - newSelectExpression._tpcDiscriminatorValues.Add(kvp.Key, kvp.Value); + newSelectExpression._tpcDiscriminatorValues[kvp.Key] = kvp.Value; } - newSelectExpression._identifier.AddRange(identifier.Zip(_identifier).Select(e => (e.First, e.Second.Comparer))); newSelectExpression._childIdentifiers.AddRange( childIdentifier.Zip(_childIdentifiers).Select(e => (e.First, e.Second.Comparer))); @@ -3827,5 +3872,8 @@ public override int GetHashCode() #if DEBUG internal bool IsMutable() => _mutable; + + internal IReadOnlyList RemovedAliases() + => _removedAliases!; #endif } diff --git a/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs b/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs index ae575a52c66..e00c168c1b3 100644 --- a/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs +++ b/src/EFCore.Relational/Query/SqlNullabilityProcessor.cs @@ -170,10 +170,6 @@ protected virtual TableExpressionBase Visit(TableExpressionBase tableExpressionB case TableExpression tableExpression: return tableExpression; - case TpcTablesExpression tpcTablesExpression: - // Since components are simple select only we can skip them. - return tpcTablesExpression; - case UnionExpression unionExpression: { var source1 = Visit(unionExpression.Source1); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs index 1e42c6ae6ab..16b29bc9f38 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs @@ -3195,17 +3195,14 @@ public override async Task Union_over_entities_with_different_nullability(bool a await base.Union_over_entities_with_different_nullability(async); AssertSql( - @"SELECT [t].[Id] -FROM ( - SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToMany_Optional_Self_Inverse1Id], [l].[OneToMany_Required_Self_Inverse1Id], [l].[OneToOne_Optional_Self1Id], [l0].[Id] AS [Id0], [l0].[Date] AS [Date0], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Name] AS [Name0], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Optional_Self_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToMany_Required_Self_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[OneToOne_Optional_Self2Id] - FROM [LevelOne] AS [l] - LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] - UNION ALL - SELECT [l2].[Id], [l2].[Date], [l2].[Name], [l2].[OneToMany_Optional_Self_Inverse1Id], [l2].[OneToMany_Required_Self_Inverse1Id], [l2].[OneToOne_Optional_Self1Id], [l1].[Id] AS [Id0], [l1].[Date] AS [Date0], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Name] AS [Name0], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Optional_Self_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToMany_Required_Self_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[OneToOne_Optional_Self2Id] - FROM [LevelTwo] AS [l1] - LEFT JOIN [LevelOne] AS [l2] ON [l1].[Level1_Optional_Id] = [l2].[Id] - WHERE [l2].[Id] IS NULL -) AS [t]"); + @"SELECT [l].[Id] +FROM [LevelOne] AS [l] +LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Optional_Id] +UNION ALL +SELECT [l2].[Id] +FROM [LevelTwo] AS [l1] +LEFT JOIN [LevelOne] AS [l2] ON [l1].[Level1_Optional_Id] = [l2].[Id] +WHERE [l2].[Id] IS NULL"); } public override async Task Including_reference_navigation_and_projecting_collection_navigation_2(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs index 4f9e9177d4f..cbddfdd68f4 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs @@ -923,35 +923,32 @@ public override async Task Union_over_entities_with_different_nullability(bool a await base.Union_over_entities_with_different_nullability(async); AssertSql( - @"SELECT [t1].[Id] -FROM ( - SELECT [l].[Id], [l].[Date], [l].[Name], [t0].[Id0], [t0].[OneToOne_Required_PK_Date], [t0].[Level1_Optional_Id], [t0].[Level1_Required_Id], [t0].[Level2_Name], [t0].[OneToMany_Optional_Inverse2Id], [t0].[OneToMany_Required_Inverse2Id], [t0].[OneToOne_Optional_PK_Inverse2Id] - FROM [Level1] AS [l] - LEFT JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] - FROM [Level1] AS [l0] - LEFT JOIN ( - SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id] - FROM [Level1] AS [l1] - WHERE [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL - ) AS [t] ON [l0].[Id] = CASE - WHEN [t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] - END - WHERE [t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL - ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] - UNION ALL - SELECT [l3].[Id], [l3].[Date], [l3].[Name], [t2].[Id] AS [Id0], [t2].[OneToOne_Required_PK_Date], [t2].[Level1_Optional_Id], [t2].[Level1_Required_Id], [t2].[Level2_Name], [t2].[OneToMany_Optional_Inverse2Id], [t2].[OneToMany_Required_Inverse2Id], [t2].[OneToOne_Optional_PK_Inverse2Id] - FROM [Level1] AS [l2] + @"SELECT [l].[Id] +FROM [Level1] AS [l] +LEFT JOIN ( + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l0] LEFT JOIN ( - SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[Level2_Name], [l4].[OneToMany_Optional_Inverse2Id], [l4].[OneToMany_Required_Inverse2Id], [l4].[OneToOne_Optional_PK_Inverse2Id] - FROM [Level1] AS [l4] - WHERE [l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL - ) AS [t2] ON [l2].[Id] = CASE - WHEN [t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] + SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id] + FROM [Level1] AS [l1] + WHERE [l1].[OneToOne_Required_PK_Date] IS NOT NULL AND [l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL + ) AS [t] ON [l0].[Id] = CASE + WHEN [t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t].[Id] END - LEFT JOIN [Level1] AS [l3] ON [t2].[Level1_Optional_Id] = [l3].[Id] - WHERE [t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL AND [l3].[Id] IS NULL -) AS [t1]"); + WHERE [t].[OneToOne_Required_PK_Date] IS NOT NULL AND [t].[Level1_Required_Id] IS NOT NULL AND [t].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] +UNION ALL +SELECT [l3].[Id] +FROM [Level1] AS [l2] +LEFT JOIN ( + SELECT [l4].[Id], [l4].[OneToOne_Required_PK_Date], [l4].[Level1_Optional_Id], [l4].[Level1_Required_Id], [l4].[OneToMany_Required_Inverse2Id] + FROM [Level1] AS [l4] + WHERE [l4].[OneToOne_Required_PK_Date] IS NOT NULL AND [l4].[Level1_Required_Id] IS NOT NULL AND [l4].[OneToMany_Required_Inverse2Id] IS NOT NULL +) AS [t2] ON [l2].[Id] = CASE + WHEN [t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [Level1] AS [l3] ON [t2].[Level1_Optional_Id] = [l3].[Id] +WHERE [t2].[OneToOne_Required_PK_Date] IS NOT NULL AND [t2].[Level1_Required_Id] IS NOT NULL AND [t2].[OneToMany_Required_Inverse2Id] IS NOT NULL AND [l3].[Id] IS NULL"); } public override async Task Distinct_skip_without_orderby(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index 28fec1e11a5..48f76cf08e8 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -1620,14 +1620,11 @@ public override async Task Concat_with_scalar_projection(bool async) await base.Concat_with_scalar_projection(async); AssertSql( - @"SELECT [t].[Nickname] -FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] - FROM [Gears] AS [g] - UNION ALL - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[Discriminator], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank] - FROM [Gears] AS [g0] -) AS [t]"); + @"SELECT [g].[Nickname] +FROM [Gears] AS [g] +UNION ALL +SELECT [g0].[Nickname] +FROM [Gears] AS [g0]"); } public override async Task Select_navigation_with_concat_and_count(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPCFiltersInheritanceQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPCFiltersInheritanceQuerySqlServerTest.cs index 37cd02d1200..96bfd2978ac 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPCFiltersInheritanceQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPCFiltersInheritanceQuerySqlServerTest.cs @@ -96,7 +96,7 @@ UNION ALL SELECT [k].[Species], [k].[CountryId], [k].[Name], [k].[EagleId], [k].[IsFlightless], NULL AS [Group], [k].[FoundOn], N'Kiwi' AS [Discriminator] FROM [Kiwi] AS [k] ) AS [t] -WHERE [t].[CountryId] = 1 AND [t].[Discriminator] IN (N'Eagle', N'Kiwi') +WHERE [t].[CountryId] = 1 ORDER BY [t].[Species]"); } @@ -113,7 +113,7 @@ UNION ALL SELECT [k].[Species], [k].[CountryId], [k].[Name], [k].[EagleId], [k].[IsFlightless], NULL AS [Group], [k].[FoundOn], N'Kiwi' AS [Discriminator] FROM [Kiwi] AS [k] ) AS [t] -WHERE [t].[CountryId] = 1 AND [t].[CountryId] = 1 AND [t].[Discriminator] IN (N'Eagle', N'Kiwi') +WHERE [t].[CountryId] = 1 AND [t].[CountryId] = 1 ORDER BY [t].[Species]"); } @@ -124,13 +124,13 @@ public override async Task Can_use_of_type_bird_with_projection(bool async) AssertSql( @"SELECT [t].[EagleId] FROM ( - SELECT [e].[CountryId], [e].[EagleId], N'Eagle' AS [Discriminator] + SELECT [e].[CountryId], [e].[EagleId] FROM [Eagle] AS [e] UNION ALL - SELECT [k].[CountryId], [k].[EagleId], N'Kiwi' AS [Discriminator] + SELECT [k].[CountryId], [k].[EagleId] FROM [Kiwi] AS [k] ) AS [t] -WHERE [t].[CountryId] = 1 AND [t].[Discriminator] IN (N'Eagle', N'Kiwi')"); +WHERE [t].[CountryId] = 1"); } public override async Task Can_use_of_type_bird_first(bool async) @@ -146,7 +146,7 @@ UNION ALL SELECT [k].[Species], [k].[CountryId], [k].[Name], [k].[EagleId], [k].[IsFlightless], NULL AS [Group], [k].[FoundOn], N'Kiwi' AS [Discriminator] FROM [Kiwi] AS [k] ) AS [t] -WHERE [t].[CountryId] = 1 AND [t].[Discriminator] IN (N'Eagle', N'Kiwi') +WHERE [t].[CountryId] = 1 ORDER BY [t].[Species]"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs index c6242e94d21..1631afe231b 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs @@ -192,8 +192,8 @@ public override async Task Include_navigation_on_derived_type(bool async) FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] @@ -212,8 +212,8 @@ public override async Task String_based_Include_navigation_on_derived_type(bool FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] @@ -413,20 +413,20 @@ public override async Task Include_with_join_and_inheritance_with_orderby_before await base.Include_with_join_and_inheritance_with_orderby_before_and_after_include(async); AssertSql( - @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t].[Id], [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator] + @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t].[Id], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] FROM [Tags] AS [t] INNER JOIN ( SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] ) AS [t0] ON [t].[GearSquadId] = [t0].[SquadId] AND [t].[GearNickName] = [t0].[Nickname] LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] -) AS [t2] ON [t0].[Nickname] = [t2].[LeaderNickname] AND [t0].[SquadId] = [t2].[LeaderSquadId] -ORDER BY [t0].[HasSoulPatch], [t0].[Nickname] DESC, [t].[Id], [t0].[SquadId], [t2].[Nickname]"); +) AS [t1] ON [t0].[Nickname] = [t1].[LeaderNickname] AND [t0].[SquadId] = [t1].[LeaderSquadId] +ORDER BY [t0].[HasSoulPatch], [t0].[Nickname] DESC, [t].[Id], [t0].[SquadId], [t1].[Nickname]"); } public override async Task Include_with_join_and_inheritance2(bool async) @@ -449,20 +449,20 @@ public override async Task Include_with_join_and_inheritance3(bool async) await base.Include_with_join_and_inheritance3(async); AssertSql( - @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t].[Id], [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator] + @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t].[Id], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] FROM [Tags] AS [t] INNER JOIN ( SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] ) AS [t0] ON [t].[GearSquadId] = [t0].[SquadId] AND [t].[GearNickName] = [t0].[Nickname] LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] -) AS [t2] ON [t0].[Nickname] = [t2].[LeaderNickname] AND [t0].[SquadId] = [t2].[LeaderSquadId] -ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t2].[Nickname]"); +) AS [t1] ON [t0].[Nickname] = [t1].[LeaderNickname] AND [t0].[SquadId] = [t1].[LeaderSquadId] +ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname]"); } public override async Task Include_with_nested_navigation_in_order_by(bool async) @@ -470,7 +470,7 @@ public override async Task Include_with_nested_navigation_in_order_by(bool async await base.Include_with_nested_navigation_in_order_by(async); AssertSql( - @"SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] + @"SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId], [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator] FROM [Weapons] AS [w] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] @@ -478,9 +478,9 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] -) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] -LEFT JOIN [Cities] AS [c] ON [t0].[CityOfBirthName] = [c].[Name] -WHERE [t0].[Nickname] <> N'Paduk' OR [t0].[Nickname] IS NULL +) AS [t] ON [w].[OwnerFullName] = [t].[FullName] +LEFT JOIN [Cities] AS [c] ON [t].[CityOfBirthName] = [c].[Name] +WHERE [t].[Nickname] <> N'Paduk' OR [t].[Nickname] IS NULL ORDER BY [c].[Name], [w].[Id]"); } @@ -1599,15 +1599,15 @@ UNION ALL SELECT [o].[Nickname], [o].[SquadId] FROM [Officers] AS [o] ) AS [t0] ON [t].[GearNickName] = [t0].[Nickname] AND [t].[GearSquadId] = [t0].[SquadId] -LEFT JOIN [Tags] AS [t2] ON ([t0].[Nickname] = [t2].[GearNickName] OR ([t0].[Nickname] IS NULL AND [t2].[GearNickName] IS NULL)) AND ([t0].[SquadId] = [t2].[GearSquadId] OR ([t0].[SquadId] IS NULL AND [t2].[GearSquadId] IS NULL)) +LEFT JOIN [Tags] AS [t1] ON ([t0].[Nickname] = [t1].[GearNickName] OR ([t0].[Nickname] IS NULL AND [t1].[GearNickName] IS NULL)) AND ([t0].[SquadId] = [t1].[GearSquadId] OR ([t0].[SquadId] IS NULL AND [t1].[GearSquadId] IS NULL)) LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName] FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName] FROM [Officers] AS [o0] -) AS [t3] ON [t2].[GearNickName] = [t3].[Nickname] AND [t2].[GearSquadId] = [t3].[SquadId] -LEFT JOIN [Cities] AS [c] ON [t3].[AssignedCityName] = [c].[Name]"); +) AS [t2] ON [t1].[GearNickName] = [t2].[Nickname] AND [t1].[GearSquadId] = [t2].[SquadId] +LEFT JOIN [Cities] AS [c] ON [t2].[AssignedCityName] = [c].[Name]"); } public override async Task Select_conditional_with_anonymous_type_and_null_constant(bool async) @@ -1774,8 +1774,8 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId] FROM [Officers] AS [o0] -) AS [t3] ON [t0].[GearNickName] = [t3].[Nickname] AND [t0].[GearSquadId] = [t3].[SquadId] -WHERE [t1].[Nickname] = [t3].[Nickname] OR ([t1].[Nickname] IS NULL AND [t3].[Nickname] IS NULL)"); +) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] +WHERE [t1].[Nickname] = [t2].[Nickname] OR ([t1].[Nickname] IS NULL AND [t2].[Nickname] IS NULL)"); } public override async Task Select_Singleton_Navigation_With_Member_Access(bool async) @@ -1833,8 +1833,8 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId] FROM [Officers] AS [o0] -) AS [t3] ON [t0].[GearNickName] = [t3].[Nickname] AND [t0].[GearSquadId] = [t3].[SquadId] -WHERE ([t1].[Nickname] = [t3].[Nickname] OR ([t1].[Nickname] IS NULL AND [t3].[Nickname] IS NULL)) AND ([t1].[SquadId] = [t3].[SquadId] OR ([t1].[SquadId] IS NULL AND [t3].[SquadId] IS NULL))"); +) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] +WHERE ([t1].[Nickname] = [t2].[Nickname] OR ([t1].[Nickname] IS NULL AND [t2].[Nickname] IS NULL)) AND ([t1].[SquadId] = [t2].[SquadId] OR ([t1].[SquadId] IS NULL AND [t2].[SquadId] IS NULL))"); } public override async Task Select_Where_Navigation_Null(bool async) @@ -1892,8 +1892,8 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId] FROM [Officers] AS [o0] -) AS [t3] ON [t0].[GearNickName] = [t3].[Nickname] AND [t0].[GearSquadId] = [t3].[SquadId] -WHERE [t1].[Nickname] = [t3].[Nickname] OR ([t1].[Nickname] IS NULL AND [t3].[Nickname] IS NULL)"); +) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] +WHERE [t1].[Nickname] = [t2].[Nickname] OR ([t1].[Nickname] IS NULL AND [t2].[Nickname] IS NULL)"); } public override async Task Optional_Navigation_Null_Coalesce_To_Clr_Type(bool async) @@ -2309,23 +2309,17 @@ public override async Task Concat_scalars_with_count(bool async) AssertSql( @"SELECT COUNT(*) FROM ( - SELECT [t].[Nickname] - FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g] - UNION ALL - SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o] - ) AS [t] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL - SELECT [t1].[FullName] AS [Nickname] - FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] - UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o0] - ) AS [t1] + SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] + FROM [Officers] AS [o] + UNION ALL + SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g0] + UNION ALL + SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] + FROM [Officers] AS [o0] ) AS [t0]"); } @@ -2361,20 +2355,17 @@ public override async Task Concat_with_scalar_projection(bool async) await base.Concat_with_scalar_projection(async); AssertSql( - @"SELECT [t0].[Nickname] -FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g] - UNION ALL - SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o] - UNION ALL - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] - UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o0] -) AS [t0]"); + @"SELECT [g].[Nickname] +FROM [Gears] AS [g] +UNION ALL +SELECT [o].[Nickname] +FROM [Officers] AS [o] +UNION ALL +SELECT [g0].[Nickname] +FROM [Gears] AS [g0] +UNION ALL +SELECT [o0].[Nickname] +FROM [Officers] AS [o0]"); } public override async Task Select_navigation_with_concat_and_count(bool async) @@ -2439,8 +2430,8 @@ SELECT COUNT(*) FROM ( SELECT [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] @@ -2449,8 +2440,8 @@ FROM [Officers] AS [o0] UNION SELECT [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator] FROM ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[AssignedCityName], [g1].[CityOfBirthName], [g1].[FullName], [g1].[HasSoulPatch], [g1].[LeaderNickname], [g1].[LeaderSquadId], [g1].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g1] + SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g0] UNION ALL SELECT [o1].[Nickname], [o1].[SquadId], [o1].[AssignedCityName], [o1].[CityOfBirthName], [o1].[FullName], [o1].[HasSoulPatch], [o1].[LeaderNickname], [o1].[LeaderSquadId], [o1].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o1] @@ -2524,7 +2515,7 @@ public override async Task Join_navigation_translated_to_subquery_composite_key( await base.Join_navigation_translated_to_subquery_composite_key(async); AssertSql( - @"SELECT [t].[FullName], [t2].[Note] + @"SELECT [t].[FullName], [t1].[Note] FROM ( SELECT [g].[FullName] FROM [Gears] AS [g] @@ -2533,7 +2524,7 @@ SELECT [o].[FullName] FROM [Officers] AS [o] ) AS [t] INNER JOIN ( - SELECT [t0].[Note], [t1].[FullName] + SELECT [t0].[Note], [t2].[FullName] FROM [Tags] AS [t0] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] @@ -2541,8 +2532,8 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName] FROM [Officers] AS [o0] - ) AS [t1] ON [t0].[GearNickName] = [t1].[Nickname] AND [t0].[GearSquadId] = [t1].[SquadId] -) AS [t2] ON [t].[FullName] = [t2].[FullName]"); + ) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] +) AS [t1] ON [t].[FullName] = [t1].[FullName]"); } public override async Task Join_with_order_by_on_inner_sequence_navigation_translated_to_subquery_composite_key(bool async) @@ -2550,7 +2541,7 @@ public override async Task Join_with_order_by_on_inner_sequence_navigation_trans await base.Join_with_order_by_on_inner_sequence_navigation_translated_to_subquery_composite_key(async); AssertSql( - @"SELECT [t].[FullName], [t2].[Note] + @"SELECT [t].[FullName], [t1].[Note] FROM ( SELECT [g].[FullName] FROM [Gears] AS [g] @@ -2559,7 +2550,7 @@ SELECT [o].[FullName] FROM [Officers] AS [o] ) AS [t] INNER JOIN ( - SELECT [t0].[Note], [t1].[FullName] + SELECT [t0].[Note], [t2].[FullName] FROM [Tags] AS [t0] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] @@ -2567,8 +2558,8 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName] FROM [Officers] AS [o0] - ) AS [t1] ON [t0].[GearNickName] = [t1].[Nickname] AND [t0].[GearSquadId] = [t1].[SquadId] -) AS [t2] ON [t].[FullName] = [t2].[FullName]"); + ) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] +) AS [t1] ON [t].[FullName] = [t1].[FullName]"); } public override async Task Join_with_order_by_without_skip_or_take(bool async) @@ -2592,7 +2583,7 @@ public override async Task Join_with_order_by_without_skip_or_take_nested(bool a await base.Join_with_order_by_without_skip_or_take_nested(async); AssertSql( - @"SELECT [w].[Name], [t0].[FullName] + @"SELECT [w].[Name], [t].[FullName] FROM [Squads] AS [s] INNER JOIN ( SELECT [g].[SquadId], [g].[FullName] @@ -2600,8 +2591,8 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] -) AS [t0] ON [s].[Id] = [t0].[SquadId] -INNER JOIN [Weapons] AS [w] ON [t0].[FullName] = [w].[OwnerFullName]"); +) AS [t] ON [s].[Id] = [t].[SquadId] +INNER JOIN [Weapons] AS [w] ON [t].[FullName] = [w].[OwnerFullName]"); } public override async Task Collection_with_inheritance_and_join_include_joined(bool async) @@ -2609,13 +2600,13 @@ public override async Task Collection_with_inheritance_and_join_include_joined(b await base.Collection_with_inheritance_and_join_include_joined(async); AssertSql( - @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t2].[Id], [t2].[GearNickName], [t2].[GearSquadId], [t2].[IssueDate], [t2].[Note] + @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t1].[Id], [t1].[GearNickName], [t1].[GearSquadId], [t1].[IssueDate], [t1].[Note] FROM [Tags] AS [t] INNER JOIN ( SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] ) AS [t0] ON [t].[GearSquadId] = [t0].[SquadId] AND [t].[GearNickName] = [t0].[Nickname] -LEFT JOIN [Tags] AS [t2] ON [t0].[Nickname] = [t2].[GearNickName] AND [t0].[SquadId] = [t2].[GearSquadId]"); +LEFT JOIN [Tags] AS [t1] ON [t0].[Nickname] = [t1].[GearNickName] AND [t0].[SquadId] = [t1].[GearSquadId]"); } public override async Task Collection_with_inheritance_and_join_include_source(bool async) @@ -3261,8 +3252,8 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] - ) AS [t2] - WHERE [t2].[SquadId] = [t0].[SquadId])"); + ) AS [t1] + WHERE [t1].[SquadId] = [t0].[SquadId])"); } public override async Task Optional_navigation_type_compensation_works_with_skip(bool async) @@ -3315,8 +3306,8 @@ FROM [Officers] AS [o] LEFT JOIN ( SELECT [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] @@ -3636,8 +3627,8 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[FullName], [o].[HasSoulPatch] FROM [Officers] AS [o] -) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] -WHERE [w].[Id] <> 50 AND [t0].[HasSoulPatch] = CAST(0 AS bit)"); +) AS [t] ON [w].[OwnerFullName] = [t].[FullName] +WHERE [w].[Id] <> 50 AND [t].[HasSoulPatch] = CAST(0 AS bit)"); } public override async Task Distinct_with_optional_navigation_is_translated_to_sql(bool async) @@ -3704,7 +3695,7 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] -) AS [t0] ON [s].[Id] = [t0].[SquadId] +) AS [t] ON [s].[Id] = [t].[SquadId] WHERE [s].[Name] = N'Kilo'"); } @@ -4205,7 +4196,7 @@ public override async Task Collection_navigation_access_on_derived_entity_using_ await base.Collection_navigation_access_on_derived_entity_using_cast_in_SelectMany(async); AssertSql( - @"SELECT [l].[Name], [t0].[Name] AS [LeaderName] + @"SELECT [l].[Name], [t].[Name] AS [LeaderName] FROM [LocustHordes] AS [l] INNER JOIN ( SELECT [l0].[Name], [l0].[LocustHordeId] @@ -4213,8 +4204,8 @@ FROM [LocustLeaders] AS [l0] UNION ALL SELECT [l1].[Name], [l1].[LocustHordeId] FROM [LocustCommanders] AS [l1] -) AS [t0] ON [l].[Id] = [t0].[LocustHordeId] -ORDER BY [t0].[Name]"); +) AS [t] ON [l].[Id] = [t].[LocustHordeId] +ORDER BY [t].[Name]"); } public override async Task Include_on_derived_entity_using_OfType(bool async) @@ -4222,7 +4213,7 @@ public override async Task Include_on_derived_entity_using_OfType(bool async) await base.Include_on_derived_entity_using_OfType(async); AssertSql( - @"SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated], [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], [t0].[Name], [t0].[LocustHordeId], [t0].[ThreatLevel], [t0].[ThreatLevelByte], [t0].[ThreatLevelNullableByte], [t0].[DefeatedByNickname], [t0].[DefeatedBySquadId], [t0].[HighCommandId], [t0].[Discriminator] + @"SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated], [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator] FROM [LocustHordes] AS [l] LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name] LEFT JOIN ( @@ -4231,7 +4222,7 @@ FROM [LocustLeaders] AS [l1] UNION ALL SELECT [l2].[Name], [l2].[LocustHordeId], [l2].[ThreatLevel], [l2].[ThreatLevelByte], [l2].[ThreatLevelNullableByte], [l2].[DefeatedByNickname], [l2].[DefeatedBySquadId], [l2].[HighCommandId], N'LocustCommander' AS [Discriminator] FROM [LocustCommanders] AS [l2] -) AS [t0] ON [l].[Id] = [t0].[LocustHordeId] +) AS [t] ON [l].[Id] = [t].[LocustHordeId] ORDER BY [l].[Name], [l].[Id], [l0].[Name]"); } @@ -4291,21 +4282,21 @@ public override async Task Comparing_two_collection_navigations_inheritance(bool await base.Comparing_two_collection_navigations_inheritance(async); AssertSql( - @"SELECT [l].[Name], [t0].[Nickname] + @"SELECT [l].[Name], [t].[Nickname] FROM [LocustHordes] AS [l] CROSS JOIN ( SELECT [o].[Nickname], [o].[SquadId], [o].[HasSoulPatch] FROM [Officers] AS [o] -) AS [t0] +) AS [t] LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name] LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId] FROM [Officers] AS [o0] -) AS [t1] ON [l0].[DefeatedByNickname] = [t1].[Nickname] AND [l0].[DefeatedBySquadId] = [t1].[SquadId] -WHERE [t0].[HasSoulPatch] = CAST(1 AS bit) AND [t1].[Nickname] = [t0].[Nickname] AND [t1].[SquadId] = [t0].[SquadId]"); +) AS [t0] ON [l0].[DefeatedByNickname] = [t0].[Nickname] AND [l0].[DefeatedBySquadId] = [t0].[SquadId] +WHERE [t].[HasSoulPatch] = CAST(1 AS bit) AND [t0].[Nickname] = [t].[Nickname] AND [t0].[SquadId] = [t].[SquadId]"); } public override async Task Comparing_entities_using_Equals_inheritance(bool async) @@ -4368,8 +4359,8 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] - ) AS [t2] - WHERE [t0].[Nickname] IS NOT NULL AND [t0].[SquadId] IS NOT NULL AND [t0].[Nickname] = [t2].[LeaderNickname] AND [t0].[SquadId] = [t2].[LeaderSquadId] AND [t2].[Nickname] = N'Dom') > 0"); + ) AS [t1] + WHERE [t0].[Nickname] IS NOT NULL AND [t0].[SquadId] IS NOT NULL AND [t0].[Nickname] = [t1].[LeaderNickname] AND [t0].[SquadId] = [t1].[LeaderSquadId] AND [t1].[Nickname] = N'Dom') > 0"); } public override async Task Select_null_conditional_with_inheritance(bool async) @@ -4401,7 +4392,7 @@ public override async Task Project_collection_navigation_with_inheritance1(bool await base.Project_collection_navigation_with_inheritance1(async); AssertSql( - @"SELECT [l].[Id], [l0].[Name], [l1].[Id], [t0].[Name], [t0].[LocustHordeId], [t0].[ThreatLevel], [t0].[ThreatLevelByte], [t0].[ThreatLevelNullableByte], [t0].[DefeatedByNickname], [t0].[DefeatedBySquadId], [t0].[HighCommandId], [t0].[Discriminator] + @"SELECT [l].[Id], [l0].[Name], [l1].[Id], [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator] FROM [LocustHordes] AS [l] LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name] LEFT JOIN [LocustHordes] AS [l1] ON [l0].[Name] = [l1].[CommanderName] @@ -4411,7 +4402,7 @@ FROM [LocustLeaders] AS [l2] UNION ALL SELECT [l3].[Name], [l3].[LocustHordeId], [l3].[ThreatLevel], [l3].[ThreatLevelByte], [l3].[ThreatLevelNullableByte], [l3].[DefeatedByNickname], [l3].[DefeatedBySquadId], [l3].[HighCommandId], N'LocustCommander' AS [Discriminator] FROM [LocustCommanders] AS [l3] -) AS [t0] ON [l1].[Id] = [t0].[LocustHordeId] +) AS [t] ON [l1].[Id] = [t].[LocustHordeId] ORDER BY [l].[Id], [l0].[Name], [l1].[Id]"); } @@ -4420,7 +4411,7 @@ public override async Task Project_collection_navigation_with_inheritance2(bool await base.Project_collection_navigation_with_inheritance2(async); AssertSql( - @"SELECT [l].[Id], [l0].[Name], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] + @"SELECT [l].[Id], [l0].[Name], [t].[Nickname], [t].[SquadId], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] FROM [LocustHordes] AS [l] LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name] LEFT JOIN ( @@ -4429,15 +4420,15 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId] FROM [Officers] AS [o] -) AS [t0] ON [l0].[DefeatedByNickname] = [t0].[Nickname] AND [l0].[DefeatedBySquadId] = [t0].[SquadId] +) AS [t] ON [l0].[DefeatedByNickname] = [t].[Nickname] AND [l0].[DefeatedBySquadId] = [t].[SquadId] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] -) AS [t1] ON ([t0].[Nickname] = [t1].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t1].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t1].[LeaderSquadId] -ORDER BY [l].[Id], [l0].[Name], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname]"); +) AS [t0] ON ([t].[Nickname] = [t0].[LeaderNickname] OR ([t].[Nickname] IS NULL AND [t0].[LeaderNickname] IS NULL)) AND [t].[SquadId] = [t0].[LeaderSquadId] +ORDER BY [l].[Id], [l0].[Name], [t].[Nickname], [t].[SquadId], [t0].[Nickname]"); } public override async Task Project_collection_navigation_with_inheritance3(bool async) @@ -4445,7 +4436,7 @@ public override async Task Project_collection_navigation_with_inheritance3(bool await base.Project_collection_navigation_with_inheritance3(async); AssertSql( - @"SELECT [l].[Id], [l0].[Name], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] + @"SELECT [l].[Id], [l0].[Name], [t].[Nickname], [t].[SquadId], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] FROM [LocustHordes] AS [l] LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name] LEFT JOIN ( @@ -4454,15 +4445,15 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId] FROM [Officers] AS [o] -) AS [t0] ON [l0].[DefeatedByNickname] = [t0].[Nickname] AND [l0].[DefeatedBySquadId] = [t0].[SquadId] +) AS [t] ON [l0].[DefeatedByNickname] = [t].[Nickname] AND [l0].[DefeatedBySquadId] = [t].[SquadId] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] -) AS [t1] ON ([t0].[Nickname] = [t1].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t1].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t1].[LeaderSquadId] -ORDER BY [l].[Id], [l0].[Name], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname]"); +) AS [t0] ON ([t].[Nickname] = [t0].[LeaderNickname] OR ([t].[Nickname] IS NULL AND [t0].[LeaderNickname] IS NULL)) AND [t].[SquadId] = [t0].[LeaderSquadId] +ORDER BY [l].[Id], [l0].[Name], [t].[Nickname], [t].[SquadId], [t0].[Nickname]"); } public override async Task Include_reference_on_derived_type_using_string(bool async) @@ -4515,7 +4506,7 @@ public override async Task Include_reference_on_derived_type_using_string_nested await base.Include_reference_on_derived_type_using_string_nested2(async); AssertSql( - @"SELECT [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator], [t2].[Name], [t2].[Location], [t2].[Nation] + @"SELECT [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator], [t1].[Name], [t1].[Location], [t1].[Nation] FROM ( SELECT [l].[Name], [l].[LocustHordeId], [l].[ThreatLevel], [l].[ThreatLevelByte], [l].[ThreatLevelNullableByte], NULL AS [DefeatedByNickname], NULL AS [DefeatedBySquadId], NULL AS [HighCommandId], N'LocustLeader' AS [Discriminator] FROM [LocustLeaders] AS [l] @@ -4531,17 +4522,17 @@ UNION ALL FROM [Officers] AS [o] ) AS [t0] ON [t].[DefeatedByNickname] = [t0].[Nickname] AND [t].[DefeatedBySquadId] = [t0].[SquadId] LEFT JOIN ( - SELECT [t3].[Nickname], [t3].[SquadId], [t3].[AssignedCityName], [t3].[CityOfBirthName], [t3].[FullName], [t3].[HasSoulPatch], [t3].[LeaderNickname], [t3].[LeaderSquadId], [t3].[Rank], [t3].[Discriminator], [c].[Name], [c].[Location], [c].[Nation] + SELECT [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator], [c].[Name], [c].[Location], [c].[Nation] FROM ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] - ) AS [t3] - INNER JOIN [Cities] AS [c] ON [t3].[CityOfBirthName] = [c].[Name] -) AS [t2] ON ([t0].[Nickname] = [t2].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t2].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t2].[LeaderSquadId] -ORDER BY [t].[Name], [t0].[Nickname], [t0].[SquadId], [t2].[Nickname], [t2].[SquadId]"); + ) AS [t2] + INNER JOIN [Cities] AS [c] ON [t2].[CityOfBirthName] = [c].[Name] +) AS [t1] ON ([t0].[Nickname] = [t1].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t1].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t1].[LeaderSquadId] +ORDER BY [t].[Name], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname], [t1].[SquadId]"); } public override async Task Include_reference_on_derived_type_using_lambda(bool async) @@ -4720,7 +4711,7 @@ public override async Task ThenInclude_collection_on_derived_after_derived_refer await base.ThenInclude_collection_on_derived_after_derived_reference(async); AssertSql( - @"SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated], [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] + @"SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated], [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] FROM [LocustHordes] AS [l] LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name] LEFT JOIN ( @@ -4729,15 +4720,15 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] -) AS [t0] ON [l0].[DefeatedByNickname] = [t0].[Nickname] AND [l0].[DefeatedBySquadId] = [t0].[SquadId] +) AS [t] ON [l0].[DefeatedByNickname] = [t].[Nickname] AND [l0].[DefeatedBySquadId] = [t].[SquadId] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] -) AS [t1] ON ([t0].[Nickname] = [t1].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t1].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t1].[LeaderSquadId] -ORDER BY [l].[Id], [l0].[Name], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname]"); +) AS [t0] ON ([t].[Nickname] = [t0].[LeaderNickname] OR ([t].[Nickname] IS NULL AND [t0].[LeaderNickname] IS NULL)) AND [t].[SquadId] = [t0].[LeaderSquadId] +ORDER BY [l].[Id], [l0].[Name], [t].[Nickname], [t].[SquadId], [t0].[Nickname]"); } public override async Task ThenInclude_collection_on_derived_after_derived_collection(bool async) @@ -4745,7 +4736,7 @@ public override async Task ThenInclude_collection_on_derived_after_derived_colle await base.ThenInclude_collection_on_derived_after_derived_collection(async); AssertSql( - @"SELECT [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator], [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator], [t2].[Nickname0], [t2].[SquadId0], [t2].[AssignedCityName0], [t2].[CityOfBirthName0], [t2].[FullName0], [t2].[HasSoulPatch0], [t2].[LeaderNickname0], [t2].[LeaderSquadId0], [t2].[Rank0], [t2].[Discriminator0] + @"SELECT [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator], [t1].[Nickname0], [t1].[SquadId0], [t1].[AssignedCityName0], [t1].[CityOfBirthName0], [t1].[FullName0], [t1].[HasSoulPatch0], [t1].[LeaderNickname0], [t1].[LeaderSquadId0], [t1].[Rank0], [t1].[Discriminator0] FROM ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g] @@ -4754,7 +4745,7 @@ UNION ALL FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t1].[Nickname] AS [Nickname0], [t1].[SquadId] AS [SquadId0], [t1].[AssignedCityName] AS [AssignedCityName0], [t1].[CityOfBirthName] AS [CityOfBirthName0], [t1].[FullName] AS [FullName0], [t1].[HasSoulPatch] AS [HasSoulPatch0], [t1].[LeaderNickname] AS [LeaderNickname0], [t1].[LeaderSquadId] AS [LeaderSquadId0], [t1].[Rank] AS [Rank0], [t1].[Discriminator] AS [Discriminator0] + SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t2].[Nickname] AS [Nickname0], [t2].[SquadId] AS [SquadId0], [t2].[AssignedCityName] AS [AssignedCityName0], [t2].[CityOfBirthName] AS [CityOfBirthName0], [t2].[FullName] AS [FullName0], [t2].[HasSoulPatch] AS [HasSoulPatch0], [t2].[LeaderNickname] AS [LeaderNickname0], [t2].[LeaderSquadId] AS [LeaderSquadId0], [t2].[Rank] AS [Rank0], [t2].[Discriminator] AS [Discriminator0] FROM ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g0] @@ -4768,9 +4759,9 @@ FROM [Gears] AS [g1] UNION ALL SELECT [o1].[Nickname], [o1].[SquadId], [o1].[AssignedCityName], [o1].[CityOfBirthName], [o1].[FullName], [o1].[HasSoulPatch], [o1].[LeaderNickname], [o1].[LeaderSquadId], [o1].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o1] - ) AS [t1] ON [t0].[Nickname] = [t1].[LeaderNickname] AND [t0].[SquadId] = [t1].[LeaderSquadId] -) AS [t2] ON [t].[Nickname] = [t2].[LeaderNickname] AND [t].[SquadId] = [t2].[LeaderSquadId] -ORDER BY [t].[Nickname], [t].[SquadId], [t2].[Nickname], [t2].[SquadId], [t2].[Nickname0]"); + ) AS [t2] ON [t0].[Nickname] = [t2].[LeaderNickname] AND [t0].[SquadId] = [t2].[LeaderSquadId] +) AS [t1] ON [t].[Nickname] = [t1].[LeaderNickname] AND [t].[SquadId] = [t1].[LeaderSquadId] +ORDER BY [t].[Nickname], [t].[SquadId], [t1].[Nickname], [t1].[SquadId], [t1].[Nickname0]"); } public override async Task ThenInclude_reference_on_derived_after_derived_collection(bool async) @@ -4778,7 +4769,7 @@ public override async Task ThenInclude_reference_on_derived_after_derived_collec await base.ThenInclude_reference_on_derived_after_derived_collection(async); AssertSql( - @"SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated], [t2].[Name], [t2].[LocustHordeId], [t2].[ThreatLevel], [t2].[ThreatLevelByte], [t2].[ThreatLevelNullableByte], [t2].[DefeatedByNickname], [t2].[DefeatedBySquadId], [t2].[HighCommandId], [t2].[Discriminator], [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator0] + @"SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated], [t1].[Name], [t1].[LocustHordeId], [t1].[ThreatLevel], [t1].[ThreatLevelByte], [t1].[ThreatLevelNullableByte], [t1].[DefeatedByNickname], [t1].[DefeatedBySquadId], [t1].[HighCommandId], [t1].[Discriminator], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator0] FROM [LocustHordes] AS [l] LEFT JOIN ( SELECT [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] AS [Discriminator0] @@ -4796,8 +4787,8 @@ UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] ) AS [t0] ON [t].[DefeatedByNickname] = [t0].[Nickname] AND [t].[DefeatedBySquadId] = [t0].[SquadId] -) AS [t2] ON [l].[Id] = [t2].[LocustHordeId] -ORDER BY [l].[Id], [t2].[Name], [t2].[Nickname]"); +) AS [t1] ON [l].[Id] = [t1].[LocustHordeId] +ORDER BY [l].[Id], [t1].[Name], [t1].[Nickname]"); } public override async Task Multiple_derived_included_on_one_method(bool async) @@ -4805,7 +4796,7 @@ public override async Task Multiple_derived_included_on_one_method(bool async) await base.Multiple_derived_included_on_one_method(async); AssertSql( - @"SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated], [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] + @"SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated], [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] FROM [LocustHordes] AS [l] LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name] LEFT JOIN ( @@ -4814,15 +4805,15 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] -) AS [t0] ON [l0].[DefeatedByNickname] = [t0].[Nickname] AND [l0].[DefeatedBySquadId] = [t0].[SquadId] +) AS [t] ON [l0].[DefeatedByNickname] = [t].[Nickname] AND [l0].[DefeatedBySquadId] = [t].[SquadId] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] -) AS [t1] ON ([t0].[Nickname] = [t1].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t1].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t1].[LeaderSquadId] -ORDER BY [l].[Id], [l0].[Name], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname]"); +) AS [t0] ON ([t].[Nickname] = [t0].[LeaderNickname] OR ([t].[Nickname] IS NULL AND [t0].[LeaderNickname] IS NULL)) AND [t].[SquadId] = [t0].[LeaderSquadId] +ORDER BY [l].[Id], [l0].[Name], [t].[Nickname], [t].[SquadId], [t0].[Nickname]"); } public override async Task Include_on_derived_multi_level(bool async) @@ -5045,8 +5036,8 @@ FROM [Officers] AS [o] LEFT JOIN ( SELECT [t1].[Nickname], [t1].[FullName], [t1].[SquadId], [t1].[LeaderNickname], [t1].[LeaderSquadId] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId] FROM [Officers] AS [o0] @@ -5151,20 +5142,17 @@ public override async Task Correlated_collections_project_anonymous_collection_r await base.Correlated_collections_project_anonymous_collection_result(async); AssertSql( - @"SELECT [s].[Name], [s].[Id], [t0].[FullName], [t0].[Rank], [t0].[Nickname], [t0].[SquadId] + @"SELECT [s].[Name], [s].[Id], [t].[FullName], [t].[Rank], [t].[Nickname], [t].[SquadId] FROM [Squads] AS [s] LEFT JOIN ( - SELECT [t].[FullName], [t].[Rank], [t].[Nickname], [t].[SquadId] - FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[Rank] - FROM [Gears] AS [g] - UNION ALL - SELECT [o].[Nickname], [o].[SquadId], [o].[FullName], [o].[Rank] - FROM [Officers] AS [o] - ) AS [t] -) AS [t0] ON [s].[Id] = [t0].[SquadId] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[Rank] + FROM [Gears] AS [g] + UNION ALL + SELECT [o].[Nickname], [o].[SquadId], [o].[FullName], [o].[Rank] + FROM [Officers] AS [o] +) AS [t] ON [s].[Id] = [t].[SquadId] WHERE [s].[Id] < 20 -ORDER BY [s].[Id], [t0].[Nickname]"); +ORDER BY [s].[Id], [t].[Nickname]"); } public override async Task Correlated_collections_nested(bool async) @@ -5243,8 +5231,8 @@ FROM [Officers] AS [o] LEFT JOIN ( SELECT [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t2].[Id], [t2].[AmmunitionType], [t2].[IsAutomatic], [t2].[Name], [t2].[OwnerFullName], [t2].[SynergyWithId], [t0].[Rank], [t0].[LeaderNickname], [t0].[LeaderSquadId] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank] FROM [Officers] AS [o0] @@ -5327,14 +5315,11 @@ FROM [Weapons] AS [w] WHERE [w].[IsAutomatic] = CAST(1 AS bit) ) AS [t0] ON [t].[FullName] = [t0].[OwnerFullName] LEFT JOIN ( - SELECT [t2].[Nickname], [t2].[Rank], [t2].[SquadId], [t2].[FullName], [t2].[LeaderNickname], [t2].[LeaderSquadId] - FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank] - FROM [Gears] AS [g0] - UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank] - FROM [Officers] AS [o0] - ) AS [t2] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] + FROM [Gears] AS [g] + UNION ALL + SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank] + FROM [Officers] AS [o0] ) AS [t1] ON [t].[Nickname] = [t1].[LeaderNickname] AND [t].[SquadId] = [t1].[LeaderSquadId] ORDER BY [t].[FullName], [t].[Nickname], [t].[SquadId], [t0].[Id], [t1].[FullName], [t1].[Nickname]"); } @@ -5353,8 +5338,8 @@ FROM [Officers] AS [o] WHERE EXISTS ( SELECT 1 FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] @@ -5368,41 +5353,41 @@ public override async Task Multiple_orderby_with_navigation_expansion_on_one_of_ await base.Multiple_orderby_with_navigation_expansion_on_one_of_the_order_bys_inside_subquery(async); AssertSql( - @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t4].[Id], [t4].[AmmunitionType], [t4].[IsAutomatic], [t4].[Name], [t4].[OwnerFullName], [t4].[SynergyWithId], [t4].[Nickname], [t4].[SquadId] + @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t3].[Id], [t3].[AmmunitionType], [t3].[IsAutomatic], [t3].[Name], [t3].[OwnerFullName], [t3].[SynergyWithId], [t3].[Nickname], [t3].[SquadId] FROM ( SELECT [o].[Nickname], [o].[SquadId], [o].[FullName], [o].[HasSoulPatch] FROM [Officers] AS [o] ) AS [t] LEFT JOIN [Tags] AS [t0] ON [t].[Nickname] = [t0].[GearNickName] AND [t].[SquadId] = [t0].[GearSquadId] LEFT JOIN ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[FullName] - FROM [Gears] AS [g1] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] + FROM [Gears] AS [g] UNION ALL - SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName] - FROM [Officers] AS [o1] + SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName] + FROM [Officers] AS [o0] ) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] LEFT JOIN ( - SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId], [t5].[Nickname], [t5].[SquadId] + SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId], [t4].[Nickname], [t4].[SquadId] FROM [Weapons] AS [w] LEFT JOIN ( - SELECT [g2].[Nickname], [g2].[SquadId], [g2].[FullName] - FROM [Gears] AS [g2] + SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] + FROM [Gears] AS [g0] UNION ALL - SELECT [o2].[Nickname], [o2].[SquadId], [o2].[FullName] - FROM [Officers] AS [o2] - ) AS [t5] ON [w].[OwnerFullName] = [t5].[FullName] -) AS [t4] ON [t2].[FullName] = [t4].[OwnerFullName] + SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName] + FROM [Officers] AS [o1] + ) AS [t4] ON [w].[OwnerFullName] = [t4].[FullName] +) AS [t3] ON [t2].[FullName] = [t3].[OwnerFullName] WHERE EXISTS ( SELECT 1 FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g1].[Nickname], [g1].[SquadId], [g1].[AssignedCityName], [g1].[CityOfBirthName], [g1].[FullName], [g1].[HasSoulPatch], [g1].[LeaderNickname], [g1].[LeaderSquadId], [g1].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g1] UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o0] + SELECT [o2].[Nickname], [o2].[SquadId], [o2].[AssignedCityName], [o2].[CityOfBirthName], [o2].[FullName], [o2].[HasSoulPatch], [o2].[LeaderNickname], [o2].[LeaderSquadId], [o2].[Rank], N'Officer' AS [Discriminator] + FROM [Officers] AS [o2] ) AS [t1] WHERE [t].[Nickname] = [t1].[LeaderNickname] AND [t].[SquadId] = [t1].[LeaderSquadId]) -ORDER BY [t].[HasSoulPatch] DESC, [t0].[Note], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t4].[IsAutomatic], [t4].[Nickname] DESC, [t4].[Id]"); +ORDER BY [t].[HasSoulPatch] DESC, [t0].[Note], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t3].[IsAutomatic], [t3].[Nickname] DESC, [t3].[Id]"); } public override async Task Multiple_orderby_with_navigation_expansion_on_one_of_the_order_bys_inside_subquery_duplicated_orderings( @@ -5411,41 +5396,41 @@ public override async Task Multiple_orderby_with_navigation_expansion_on_one_of_ await base.Multiple_orderby_with_navigation_expansion_on_one_of_the_order_bys_inside_subquery_duplicated_orderings(async); AssertSql( - @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t4].[Id], [t4].[AmmunitionType], [t4].[IsAutomatic], [t4].[Name], [t4].[OwnerFullName], [t4].[SynergyWithId], [t4].[Nickname], [t4].[SquadId] + @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t3].[Id], [t3].[AmmunitionType], [t3].[IsAutomatic], [t3].[Name], [t3].[OwnerFullName], [t3].[SynergyWithId], [t3].[Nickname], [t3].[SquadId] FROM ( SELECT [o].[Nickname], [o].[SquadId], [o].[FullName], [o].[HasSoulPatch] FROM [Officers] AS [o] ) AS [t] LEFT JOIN [Tags] AS [t0] ON [t].[Nickname] = [t0].[GearNickName] AND [t].[SquadId] = [t0].[GearSquadId] LEFT JOIN ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[FullName] - FROM [Gears] AS [g1] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] + FROM [Gears] AS [g] UNION ALL - SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName] - FROM [Officers] AS [o1] + SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName] + FROM [Officers] AS [o0] ) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] LEFT JOIN ( - SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId], [t5].[Nickname], [t5].[SquadId] + SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId], [t4].[Nickname], [t4].[SquadId] FROM [Weapons] AS [w] LEFT JOIN ( - SELECT [g2].[Nickname], [g2].[SquadId], [g2].[FullName] - FROM [Gears] AS [g2] + SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] + FROM [Gears] AS [g0] UNION ALL - SELECT [o2].[Nickname], [o2].[SquadId], [o2].[FullName] - FROM [Officers] AS [o2] - ) AS [t5] ON [w].[OwnerFullName] = [t5].[FullName] -) AS [t4] ON [t2].[FullName] = [t4].[OwnerFullName] + SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName] + FROM [Officers] AS [o1] + ) AS [t4] ON [w].[OwnerFullName] = [t4].[FullName] +) AS [t3] ON [t2].[FullName] = [t3].[OwnerFullName] WHERE EXISTS ( SELECT 1 FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g1].[Nickname], [g1].[SquadId], [g1].[AssignedCityName], [g1].[CityOfBirthName], [g1].[FullName], [g1].[HasSoulPatch], [g1].[LeaderNickname], [g1].[LeaderSquadId], [g1].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g1] UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o0] + SELECT [o2].[Nickname], [o2].[SquadId], [o2].[AssignedCityName], [o2].[CityOfBirthName], [o2].[FullName], [o2].[HasSoulPatch], [o2].[LeaderNickname], [o2].[LeaderSquadId], [o2].[Rank], N'Officer' AS [Discriminator] + FROM [Officers] AS [o2] ) AS [t1] WHERE [t].[Nickname] = [t1].[LeaderNickname] AND [t].[SquadId] = [t1].[LeaderSquadId]) -ORDER BY [t].[HasSoulPatch] DESC, [t0].[Note], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t4].[IsAutomatic], [t4].[Nickname] DESC, [t4].[Id]"); +ORDER BY [t].[HasSoulPatch] DESC, [t0].[Note], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t3].[IsAutomatic], [t3].[Nickname] DESC, [t3].[Id]"); } public override async Task Multiple_orderby_with_navigation_expansion_on_one_of_the_order_bys_inside_subquery_complex_orderings( @@ -5454,44 +5439,44 @@ public override async Task Multiple_orderby_with_navigation_expansion_on_one_of_ await base.Multiple_orderby_with_navigation_expansion_on_one_of_the_order_bys_inside_subquery_complex_orderings(async); AssertSql( - @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t4].[Id], [t4].[AmmunitionType], [t4].[IsAutomatic], [t4].[Name], [t4].[OwnerFullName], [t4].[SynergyWithId], [t4].[Nickname], [t4].[SquadId] + @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t3].[Id], [t3].[AmmunitionType], [t3].[IsAutomatic], [t3].[Name], [t3].[OwnerFullName], [t3].[SynergyWithId], [t3].[Nickname], [t3].[SquadId] FROM ( SELECT [o].[Nickname], [o].[SquadId], [o].[FullName], [o].[HasSoulPatch] FROM [Officers] AS [o] ) AS [t] LEFT JOIN [Tags] AS [t0] ON [t].[Nickname] = [t0].[GearNickName] AND [t].[SquadId] = [t0].[GearSquadId] LEFT JOIN ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[FullName] - FROM [Gears] AS [g1] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] + FROM [Gears] AS [g] UNION ALL - SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName] - FROM [Officers] AS [o1] + SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName] + FROM [Officers] AS [o0] ) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] LEFT JOIN ( - SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId], [t5].[Nickname], [t5].[SquadId], ( + SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId], [t4].[Nickname], [t4].[SquadId], ( SELECT COUNT(*) FROM [Weapons] AS [w0] - WHERE [t5].[FullName] IS NOT NULL AND [t5].[FullName] = [w0].[OwnerFullName]) AS [c] + WHERE [t4].[FullName] IS NOT NULL AND [t4].[FullName] = [w0].[OwnerFullName]) AS [c] FROM [Weapons] AS [w] LEFT JOIN ( - SELECT [g2].[Nickname], [g2].[SquadId], [g2].[FullName] - FROM [Gears] AS [g2] + SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] + FROM [Gears] AS [g0] UNION ALL - SELECT [o2].[Nickname], [o2].[SquadId], [o2].[FullName] - FROM [Officers] AS [o2] - ) AS [t5] ON [w].[OwnerFullName] = [t5].[FullName] -) AS [t4] ON [t2].[FullName] = [t4].[OwnerFullName] + SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName] + FROM [Officers] AS [o1] + ) AS [t4] ON [w].[OwnerFullName] = [t4].[FullName] +) AS [t3] ON [t2].[FullName] = [t3].[OwnerFullName] WHERE EXISTS ( SELECT 1 FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g1].[Nickname], [g1].[SquadId], [g1].[AssignedCityName], [g1].[CityOfBirthName], [g1].[FullName], [g1].[HasSoulPatch], [g1].[LeaderNickname], [g1].[LeaderSquadId], [g1].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g1] UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o0] + SELECT [o2].[Nickname], [o2].[SquadId], [o2].[AssignedCityName], [o2].[CityOfBirthName], [o2].[FullName], [o2].[HasSoulPatch], [o2].[LeaderNickname], [o2].[LeaderSquadId], [o2].[Rank], N'Officer' AS [Discriminator] + FROM [Officers] AS [o2] ) AS [t1] WHERE [t].[Nickname] = [t1].[LeaderNickname] AND [t].[SquadId] = [t1].[LeaderSquadId]) -ORDER BY [t].[HasSoulPatch] DESC, [t0].[Note], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t4].[Id] DESC, [t4].[c], [t4].[Nickname]"); +ORDER BY [t].[HasSoulPatch] DESC, [t0].[Note], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t3].[Id] DESC, [t3].[c], [t3].[Nickname]"); } public override async Task Correlated_collections_multiple_nested_complex_collections(bool async) @@ -5499,76 +5484,73 @@ public override async Task Correlated_collections_multiple_nested_complex_collec await base.Correlated_collections_multiple_nested_complex_collections(async); AssertSql( - @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t5].[FullName], [t5].[Nickname], [t5].[SquadId], [t5].[Id], [t5].[Nickname0], [t5].[SquadId0], [t5].[Id0], [t5].[Name], [t5].[IsAutomatic], [t5].[Id1], [t5].[Nickname00], [t5].[HasSoulPatch], [t5].[SquadId00], [t11].[Id], [t11].[AmmunitionType], [t11].[IsAutomatic], [t11].[Name], [t11].[OwnerFullName], [t11].[SynergyWithId], [t11].[Nickname], [t11].[SquadId] + @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t3].[FullName], [t3].[Nickname], [t3].[SquadId], [t3].[Id], [t3].[Nickname0], [t3].[SquadId0], [t3].[Id0], [t3].[Name], [t3].[IsAutomatic], [t3].[Id1], [t3].[Nickname00], [t3].[HasSoulPatch], [t3].[SquadId00], [t8].[Id], [t8].[AmmunitionType], [t8].[IsAutomatic], [t8].[Name], [t8].[OwnerFullName], [t8].[SynergyWithId], [t8].[Nickname], [t8].[SquadId] FROM ( SELECT [o].[Nickname], [o].[SquadId], [o].[FullName], [o].[HasSoulPatch] FROM [Officers] AS [o] ) AS [t] LEFT JOIN [Tags] AS [t0] ON [t].[Nickname] = [t0].[GearNickName] AND [t].[SquadId] = [t0].[GearSquadId] LEFT JOIN ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[FullName] - FROM [Gears] AS [g1] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] + FROM [Gears] AS [g] UNION ALL - SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName] - FROM [Officers] AS [o1] + SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName] + FROM [Officers] AS [o0] ) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] LEFT JOIN ( - SELECT [t4].[FullName], [t4].[Nickname], [t4].[SquadId], [t6].[Id], [t6].[Nickname] AS [Nickname0], [t6].[SquadId] AS [SquadId0], [t6].[Id0], [t6].[Name], [t6].[IsAutomatic], [t6].[Id1], [t6].[Nickname0] AS [Nickname00], [t6].[HasSoulPatch], [t6].[SquadId0] AS [SquadId00], [t4].[Rank], [t6].[IsAutomatic0], [t4].[LeaderNickname], [t4].[LeaderSquadId] + SELECT [t4].[FullName], [t4].[Nickname], [t4].[SquadId], [t5].[Id], [t5].[Nickname] AS [Nickname0], [t5].[SquadId] AS [SquadId0], [t5].[Id0], [t5].[Name], [t5].[IsAutomatic], [t5].[Id1], [t5].[Nickname0] AS [Nickname00], [t5].[HasSoulPatch], [t5].[SquadId0] AS [SquadId00], [t4].[Rank], [t5].[IsAutomatic0], [t4].[LeaderNickname], [t4].[LeaderSquadId] FROM ( - SELECT [g2].[Nickname], [g2].[SquadId], [g2].[FullName], [g2].[LeaderNickname], [g2].[LeaderSquadId], [g2].[Rank] - FROM [Gears] AS [g2] + SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank] + FROM [Gears] AS [g0] UNION ALL - SELECT [o2].[Nickname], [o2].[SquadId], [o2].[FullName], [o2].[LeaderNickname], [o2].[LeaderSquadId], [o2].[Rank] - FROM [Officers] AS [o2] + SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName], [o1].[LeaderNickname], [o1].[LeaderSquadId], [o1].[Rank] + FROM [Officers] AS [o1] ) AS [t4] LEFT JOIN ( - SELECT [w].[Id], [t7].[Nickname], [t7].[SquadId], [s].[Id] AS [Id0], [w0].[Name], [w0].[IsAutomatic], [w0].[Id] AS [Id1], [t8].[Nickname] AS [Nickname0], [t8].[HasSoulPatch], [t8].[SquadId] AS [SquadId0], [w].[IsAutomatic] AS [IsAutomatic0], [w].[OwnerFullName] + SELECT [w].[Id], [t6].[Nickname], [t6].[SquadId], [s].[Id] AS [Id0], [w0].[Name], [w0].[IsAutomatic], [w0].[Id] AS [Id1], [t7].[Nickname] AS [Nickname0], [t7].[HasSoulPatch], [t7].[SquadId] AS [SquadId0], [w].[IsAutomatic] AS [IsAutomatic0], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN ( - SELECT [g3].[Nickname], [g3].[SquadId], [g3].[FullName] - FROM [Gears] AS [g3] + SELECT [g1].[Nickname], [g1].[SquadId], [g1].[FullName] + FROM [Gears] AS [g1] UNION ALL - SELECT [o3].[Nickname], [o3].[SquadId], [o3].[FullName] - FROM [Officers] AS [o3] - ) AS [t7] ON [w].[OwnerFullName] = [t7].[FullName] - LEFT JOIN [Squads] AS [s] ON [t7].[SquadId] = [s].[Id] - LEFT JOIN [Weapons] AS [w0] ON [t7].[FullName] = [w0].[OwnerFullName] + SELECT [o2].[Nickname], [o2].[SquadId], [o2].[FullName] + FROM [Officers] AS [o2] + ) AS [t6] ON [w].[OwnerFullName] = [t6].[FullName] + LEFT JOIN [Squads] AS [s] ON [t6].[SquadId] = [s].[Id] + LEFT JOIN [Weapons] AS [w0] ON [t6].[FullName] = [w0].[OwnerFullName] LEFT JOIN ( - SELECT [t10].[Nickname], [t10].[HasSoulPatch], [t10].[SquadId] - FROM ( - SELECT [g4].[Nickname], [g4].[SquadId], [g4].[HasSoulPatch] - FROM [Gears] AS [g4] - UNION ALL - SELECT [o4].[Nickname], [o4].[SquadId], [o4].[HasSoulPatch] - FROM [Officers] AS [o4] - ) AS [t10] - ) AS [t8] ON [s].[Id] = [t8].[SquadId] + SELECT [g2].[Nickname], [g2].[SquadId], [g2].[HasSoulPatch] + FROM [Gears] AS [g2] + UNION ALL + SELECT [o3].[Nickname], [o3].[SquadId], [o3].[HasSoulPatch] + FROM [Officers] AS [o3] + ) AS [t7] ON [s].[Id] = [t7].[SquadId] WHERE [w].[Name] <> N'Bar' OR [w].[Name] IS NULL - ) AS [t6] ON [t4].[FullName] = [t6].[OwnerFullName] + ) AS [t5] ON [t4].[FullName] = [t5].[OwnerFullName] WHERE [t4].[FullName] <> N'Foo' -) AS [t5] ON [t].[Nickname] = [t5].[LeaderNickname] AND [t].[SquadId] = [t5].[LeaderSquadId] +) AS [t3] ON [t].[Nickname] = [t3].[LeaderNickname] AND [t].[SquadId] = [t3].[LeaderSquadId] LEFT JOIN ( - SELECT [w1].[Id], [w1].[AmmunitionType], [w1].[IsAutomatic], [w1].[Name], [w1].[OwnerFullName], [w1].[SynergyWithId], [t12].[Nickname], [t12].[SquadId] + SELECT [w1].[Id], [w1].[AmmunitionType], [w1].[IsAutomatic], [w1].[Name], [w1].[OwnerFullName], [w1].[SynergyWithId], [t9].[Nickname], [t9].[SquadId] FROM [Weapons] AS [w1] LEFT JOIN ( - SELECT [g5].[Nickname], [g5].[SquadId], [g5].[FullName] - FROM [Gears] AS [g5] + SELECT [g3].[Nickname], [g3].[SquadId], [g3].[FullName] + FROM [Gears] AS [g3] UNION ALL - SELECT [o5].[Nickname], [o5].[SquadId], [o5].[FullName] - FROM [Officers] AS [o5] - ) AS [t12] ON [w1].[OwnerFullName] = [t12].[FullName] -) AS [t11] ON [t2].[FullName] = [t11].[OwnerFullName] + SELECT [o4].[Nickname], [o4].[SquadId], [o4].[FullName] + FROM [Officers] AS [o4] + ) AS [t9] ON [w1].[OwnerFullName] = [t9].[FullName] +) AS [t8] ON [t2].[FullName] = [t8].[OwnerFullName] WHERE EXISTS ( SELECT 1 FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g4].[Nickname], [g4].[SquadId], [g4].[AssignedCityName], [g4].[CityOfBirthName], [g4].[FullName], [g4].[HasSoulPatch], [g4].[LeaderNickname], [g4].[LeaderSquadId], [g4].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g4] UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o0] + SELECT [o5].[Nickname], [o5].[SquadId], [o5].[AssignedCityName], [o5].[CityOfBirthName], [o5].[FullName], [o5].[HasSoulPatch], [o5].[LeaderNickname], [o5].[LeaderSquadId], [o5].[Rank], N'Officer' AS [Discriminator] + FROM [Officers] AS [o5] ) AS [t1] WHERE [t].[Nickname] = [t1].[LeaderNickname] AND [t].[SquadId] = [t1].[LeaderSquadId]) -ORDER BY [t].[HasSoulPatch] DESC, [t0].[Note], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t5].[Rank], [t5].[Nickname], [t5].[SquadId], [t5].[IsAutomatic0], [t5].[Id], [t5].[Nickname0], [t5].[SquadId0], [t5].[Id0], [t5].[Id1], [t5].[Nickname00], [t5].[SquadId00], [t11].[IsAutomatic], [t11].[Nickname] DESC, [t11].[Id]"); +ORDER BY [t].[HasSoulPatch] DESC, [t0].[Note], [t].[Nickname], [t].[SquadId], [t0].[Id], [t2].[Nickname], [t2].[SquadId], [t3].[Rank], [t3].[Nickname], [t3].[SquadId], [t3].[IsAutomatic0], [t3].[Id], [t3].[Nickname0], [t3].[SquadId0], [t3].[Id0], [t3].[Id1], [t3].[Nickname00], [t3].[SquadId00], [t8].[IsAutomatic], [t8].[Nickname] DESC, [t8].[Id]"); } public override async Task Correlated_collections_inner_subquery_selector_references_outer_qsre(bool async) @@ -5584,8 +5566,8 @@ FROM [Officers] AS [o] OUTER APPLY ( SELECT [t1].[FullName] AS [ReportName], [t].[FullName] AS [OfficerName], [t1].[Nickname], [t1].[SquadId] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[LeaderNickname], [g].[LeaderSquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId] FROM [Officers] AS [o0] @@ -5608,8 +5590,8 @@ FROM [Officers] AS [o] OUTER APPLY ( SELECT [t1].[FullName] AS [ReportName], [t1].[Nickname], [t1].[SquadId] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[LeaderNickname], [g].[LeaderSquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId] FROM [Officers] AS [o0] @@ -5632,8 +5614,8 @@ FROM [Officers] AS [o] LEFT JOIN ( SELECT [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t2].[Name], [t2].[Nickname] AS [Nickname0], [t2].[Id], [t0].[LeaderNickname], [t0].[LeaderSquadId] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[LeaderNickname], [g].[LeaderSquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId] FROM [Officers] AS [o0] @@ -5661,8 +5643,8 @@ FROM [Officers] AS [o] OUTER APPLY ( SELECT [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t2].[Name], [t2].[Nickname] AS [Nickname0], [t2].[Id] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[LeaderNickname], [g].[LeaderSquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId] FROM [Officers] AS [o0] @@ -5847,23 +5829,20 @@ public override async Task Correlated_collections_left_join_with_self_reference( await base.Correlated_collections_left_join_with_self_reference(async); AssertSql( - @"SELECT [t].[Note], [t].[Id], [t0].[Nickname], [t0].[SquadId], [t2].[FullName], [t2].[Nickname], [t2].[SquadId] + @"SELECT [t].[Note], [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[FullName], [t1].[Nickname], [t1].[SquadId] FROM [Tags] AS [t] LEFT JOIN ( SELECT [o].[Nickname], [o].[SquadId] FROM [Officers] AS [o] ) AS [t0] ON [t].[GearNickName] = [t0].[Nickname] LEFT JOIN ( - SELECT [t3].[FullName], [t3].[Nickname], [t3].[SquadId], [t3].[LeaderNickname], [t3].[LeaderSquadId] - FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] - UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId] - FROM [Officers] AS [o0] - ) AS [t3] -) AS [t2] ON ([t0].[Nickname] = [t2].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t2].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t2].[LeaderSquadId] -ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t2].[Nickname]"); + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[LeaderNickname], [g].[LeaderSquadId] + FROM [Gears] AS [g] + UNION ALL + SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId] + FROM [Officers] AS [o0] +) AS [t1] ON ([t0].[Nickname] = [t1].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t1].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t1].[LeaderSquadId] +ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname]"); } public override async Task Correlated_collections_deeply_nested_left_join(bool async) @@ -5871,7 +5850,7 @@ public override async Task Correlated_collections_deeply_nested_left_join(bool a await base.Correlated_collections_deeply_nested_left_join(async); AssertSql( - @"SELECT [t].[Id], [t0].[Nickname], [t0].[SquadId], [s].[Id], [t2].[Nickname], [t2].[SquadId], [t2].[Id], [t2].[AmmunitionType], [t2].[IsAutomatic], [t2].[Name], [t2].[OwnerFullName], [t2].[SynergyWithId] + @"SELECT [t].[Id], [t0].[Nickname], [t0].[SquadId], [s].[Id], [t1].[Nickname], [t1].[SquadId], [t1].[Id], [t1].[AmmunitionType], [t1].[IsAutomatic], [t1].[Name], [t1].[OwnerFullName], [t1].[SynergyWithId] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId] @@ -5882,22 +5861,22 @@ FROM [Officers] AS [o] ) AS [t0] ON [t].[GearNickName] = [t0].[Nickname] LEFT JOIN [Squads] AS [s] ON [t0].[SquadId] = [s].[Id] LEFT JOIN ( - SELECT [t3].[Nickname], [t3].[SquadId], [t4].[Id], [t4].[AmmunitionType], [t4].[IsAutomatic], [t4].[Name], [t4].[OwnerFullName], [t4].[SynergyWithId] + SELECT [t2].[Nickname], [t2].[SquadId], [t3].[Id], [t3].[AmmunitionType], [t3].[IsAutomatic], [t3].[Name], [t3].[OwnerFullName], [t3].[SynergyWithId] FROM ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[HasSoulPatch] FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[HasSoulPatch] FROM [Officers] AS [o0] - ) AS [t3] + ) AS [t2] LEFT JOIN ( SELECT [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM [Weapons] AS [w] WHERE [w].[IsAutomatic] = CAST(1 AS bit) - ) AS [t4] ON [t3].[FullName] = [t4].[OwnerFullName] - WHERE [t3].[HasSoulPatch] = CAST(1 AS bit) -) AS [t2] ON [s].[Id] = [t2].[SquadId] -ORDER BY [t].[Note], [t0].[Nickname] DESC, [t].[Id], [t0].[SquadId], [s].[Id], [t2].[Nickname], [t2].[SquadId]"); + ) AS [t3] ON [t2].[FullName] = [t3].[OwnerFullName] + WHERE [t2].[HasSoulPatch] = CAST(1 AS bit) +) AS [t1] ON [s].[Id] = [t1].[SquadId] +ORDER BY [t].[Note], [t0].[Nickname] DESC, [t].[Id], [t0].[SquadId], [s].[Id], [t1].[Nickname], [t1].[SquadId]"); } public override async Task Correlated_collections_from_left_join_with_additional_elements_projected_of_that_join(bool async) @@ -5905,7 +5884,7 @@ public override async Task Correlated_collections_from_left_join_with_additional await base.Correlated_collections_from_left_join_with_additional_elements_projected_of_that_join(async); AssertSql( - @"SELECT [w].[Id], [t0].[Nickname], [t0].[SquadId], [s].[Id], [t1].[Nickname], [t1].[SquadId], [t1].[Id], [t1].[AmmunitionType], [t1].[IsAutomatic], [t1].[Name], [t1].[OwnerFullName], [t1].[SynergyWithId], [t1].[Rank] + @"SELECT [w].[Id], [t].[Nickname], [t].[SquadId], [s].[Id], [t1].[Nickname], [t1].[SquadId], [t1].[Id], [t1].[AmmunitionType], [t1].[IsAutomatic], [t1].[Name], [t1].[OwnerFullName], [t1].[SynergyWithId], [t1].[Rank] FROM [Weapons] AS [w] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] @@ -5913,24 +5892,24 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] -) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] -LEFT JOIN [Squads] AS [s] ON [t0].[SquadId] = [s].[Id] +) AS [t] ON [w].[OwnerFullName] = [t].[FullName] +LEFT JOIN [Squads] AS [s] ON [t].[SquadId] = [s].[Id] LEFT JOIN ( - SELECT [t2].[Nickname], [t2].[SquadId], [t3].[Id], [t3].[AmmunitionType], [t3].[IsAutomatic], [t3].[Name], [t3].[OwnerFullName], [t3].[SynergyWithId], [t2].[Rank], [t2].[FullName] + SELECT [t0].[Nickname], [t0].[SquadId], [t2].[Id], [t2].[AmmunitionType], [t2].[IsAutomatic], [t2].[Name], [t2].[OwnerFullName], [t2].[SynergyWithId], [t0].[Rank], [t0].[FullName] FROM ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[Rank] FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[Rank] FROM [Officers] AS [o0] - ) AS [t2] + ) AS [t0] LEFT JOIN ( SELECT [w0].[Id], [w0].[AmmunitionType], [w0].[IsAutomatic], [w0].[Name], [w0].[OwnerFullName], [w0].[SynergyWithId] FROM [Weapons] AS [w0] WHERE [w0].[IsAutomatic] = CAST(0 AS bit) - ) AS [t3] ON [t2].[FullName] = [t3].[OwnerFullName] + ) AS [t2] ON [t0].[FullName] = [t2].[OwnerFullName] ) AS [t1] ON [s].[Id] = [t1].[SquadId] -ORDER BY [w].[Name], [w].[Id], [t0].[Nickname], [t0].[SquadId], [s].[Id], [t1].[FullName] DESC, [t1].[Nickname], [t1].[SquadId], [t1].[Id]"); +ORDER BY [w].[Name], [w].[Id], [t].[Nickname], [t].[SquadId], [s].[Id], [t1].[FullName] DESC, [t1].[Nickname], [t1].[SquadId], [t1].[Id]"); } public override async Task Correlated_collections_complex_scenario1(bool async) @@ -5938,7 +5917,7 @@ public override async Task Correlated_collections_complex_scenario1(bool async) await base.Correlated_collections_complex_scenario1(async); AssertSql( - @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t3].[Id], [t3].[Nickname], [t3].[SquadId], [t3].[Id0], [t3].[Nickname0], [t3].[HasSoulPatch], [t3].[SquadId0] + @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t1].[Id], [t1].[Nickname], [t1].[SquadId], [t1].[Id0], [t1].[Nickname0], [t1].[HasSoulPatch], [t1].[SquadId0] FROM ( SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] FROM [Gears] AS [g] @@ -5947,7 +5926,7 @@ UNION ALL FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [w].[Id], [t0].[Nickname], [t0].[SquadId], [s].[Id] AS [Id0], [t1].[Nickname] AS [Nickname0], [t1].[HasSoulPatch], [t1].[SquadId] AS [SquadId0], [w].[OwnerFullName] + SELECT [w].[Id], [t0].[Nickname], [t0].[SquadId], [s].[Id] AS [Id0], [t2].[Nickname] AS [Nickname0], [t2].[HasSoulPatch], [t2].[SquadId] AS [SquadId0], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] @@ -5958,17 +5937,14 @@ FROM [Officers] AS [o0] ) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] LEFT JOIN [Squads] AS [s] ON [t0].[SquadId] = [s].[Id] LEFT JOIN ( - SELECT [t4].[Nickname], [t4].[HasSoulPatch], [t4].[SquadId] - FROM ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[HasSoulPatch] - FROM [Gears] AS [g1] - UNION ALL - SELECT [o1].[Nickname], [o1].[SquadId], [o1].[HasSoulPatch] - FROM [Officers] AS [o1] - ) AS [t4] - ) AS [t1] ON [s].[Id] = [t1].[SquadId] -) AS [t3] ON [t].[FullName] = [t3].[OwnerFullName] -ORDER BY [t].[Nickname], [t].[SquadId], [t3].[Id], [t3].[Nickname], [t3].[SquadId], [t3].[Id0], [t3].[Nickname0]"); + SELECT [g1].[Nickname], [g1].[SquadId], [g1].[HasSoulPatch] + FROM [Gears] AS [g1] + UNION ALL + SELECT [o1].[Nickname], [o1].[SquadId], [o1].[HasSoulPatch] + FROM [Officers] AS [o1] + ) AS [t2] ON [s].[Id] = [t2].[SquadId] +) AS [t1] ON [t].[FullName] = [t1].[OwnerFullName] +ORDER BY [t].[Nickname], [t].[SquadId], [t1].[Id], [t1].[Nickname], [t1].[SquadId], [t1].[Id0], [t1].[Nickname0]"); } public override async Task Correlated_collections_complex_scenario2(bool async) @@ -5976,44 +5952,41 @@ public override async Task Correlated_collections_complex_scenario2(bool async) await base.Correlated_collections_complex_scenario2(async); AssertSql( - @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t5].[FullName], [t5].[Nickname], [t5].[SquadId], [t5].[Id], [t5].[Nickname0], [t5].[SquadId0], [t5].[Id0], [t5].[Nickname00], [t5].[HasSoulPatch], [t5].[SquadId00] + @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t3].[FullName], [t3].[Nickname], [t3].[SquadId], [t3].[Id], [t3].[Nickname0], [t3].[SquadId0], [t3].[Id0], [t3].[Nickname00], [t3].[HasSoulPatch], [t3].[SquadId00] FROM ( SELECT [o].[Nickname], [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t3].[Id], [t3].[Nickname] AS [Nickname0], [t3].[SquadId] AS [SquadId0], [t3].[Id0], [t3].[Nickname0] AS [Nickname00], [t3].[HasSoulPatch], [t3].[SquadId0] AS [SquadId00], [t0].[LeaderNickname], [t0].[LeaderSquadId] + SELECT [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t1].[Id], [t1].[Nickname] AS [Nickname0], [t1].[SquadId] AS [SquadId0], [t1].[Id0], [t1].[Nickname0] AS [Nickname00], [t1].[HasSoulPatch], [t1].[SquadId0] AS [SquadId00], [t0].[LeaderNickname], [t0].[LeaderSquadId] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[LeaderNickname], [g].[LeaderSquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId] FROM [Officers] AS [o0] ) AS [t0] LEFT JOIN ( - SELECT [w].[Id], [t1].[Nickname], [t1].[SquadId], [s].[Id] AS [Id0], [t2].[Nickname] AS [Nickname0], [t2].[HasSoulPatch], [t2].[SquadId] AS [SquadId0], [w].[OwnerFullName] + SELECT [w].[Id], [t2].[Nickname], [t2].[SquadId], [s].[Id] AS [Id0], [t4].[Nickname] AS [Nickname0], [t4].[HasSoulPatch], [t4].[SquadId] AS [SquadId0], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[FullName] - FROM [Gears] AS [g1] + SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] + FROM [Gears] AS [g0] UNION ALL SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName] FROM [Officers] AS [o1] - ) AS [t1] ON [w].[OwnerFullName] = [t1].[FullName] - LEFT JOIN [Squads] AS [s] ON [t1].[SquadId] = [s].[Id] + ) AS [t2] ON [w].[OwnerFullName] = [t2].[FullName] + LEFT JOIN [Squads] AS [s] ON [t2].[SquadId] = [s].[Id] LEFT JOIN ( - SELECT [t6].[Nickname], [t6].[HasSoulPatch], [t6].[SquadId] - FROM ( - SELECT [g2].[Nickname], [g2].[SquadId], [g2].[HasSoulPatch] - FROM [Gears] AS [g2] - UNION ALL - SELECT [o2].[Nickname], [o2].[SquadId], [o2].[HasSoulPatch] - FROM [Officers] AS [o2] - ) AS [t6] - ) AS [t2] ON [s].[Id] = [t2].[SquadId] - ) AS [t3] ON [t0].[FullName] = [t3].[OwnerFullName] -) AS [t5] ON [t].[Nickname] = [t5].[LeaderNickname] AND [t].[SquadId] = [t5].[LeaderSquadId] -ORDER BY [t].[Nickname], [t].[SquadId], [t5].[Nickname], [t5].[SquadId], [t5].[Id], [t5].[Nickname0], [t5].[SquadId0], [t5].[Id0], [t5].[Nickname00]"); + SELECT [g1].[Nickname], [g1].[SquadId], [g1].[HasSoulPatch] + FROM [Gears] AS [g1] + UNION ALL + SELECT [o2].[Nickname], [o2].[SquadId], [o2].[HasSoulPatch] + FROM [Officers] AS [o2] + ) AS [t4] ON [s].[Id] = [t4].[SquadId] + ) AS [t1] ON [t0].[FullName] = [t1].[OwnerFullName] +) AS [t3] ON [t].[Nickname] = [t3].[LeaderNickname] AND [t].[SquadId] = [t3].[LeaderSquadId] +ORDER BY [t].[Nickname], [t].[SquadId], [t3].[Nickname], [t3].[SquadId], [t3].[Id], [t3].[Nickname0], [t3].[SquadId0], [t3].[Id0], [t3].[Nickname00]"); } public override async Task Correlated_collections_with_funky_orderby_complex_scenario1(bool async) @@ -6021,7 +5994,7 @@ public override async Task Correlated_collections_with_funky_orderby_complex_sce await base.Correlated_collections_with_funky_orderby_complex_scenario1(async); AssertSql( - @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t3].[Id], [t3].[Nickname], [t3].[SquadId], [t3].[Id0], [t3].[Nickname0], [t3].[HasSoulPatch], [t3].[SquadId0] + @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t1].[Id], [t1].[Nickname], [t1].[SquadId], [t1].[Id0], [t1].[Nickname0], [t1].[HasSoulPatch], [t1].[SquadId0] FROM ( SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] FROM [Gears] AS [g] @@ -6030,7 +6003,7 @@ UNION ALL FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [w].[Id], [t0].[Nickname], [t0].[SquadId], [s].[Id] AS [Id0], [t1].[Nickname] AS [Nickname0], [t1].[HasSoulPatch], [t1].[SquadId] AS [SquadId0], [w].[OwnerFullName] + SELECT [w].[Id], [t0].[Nickname], [t0].[SquadId], [s].[Id] AS [Id0], [t2].[Nickname] AS [Nickname0], [t2].[HasSoulPatch], [t2].[SquadId] AS [SquadId0], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] @@ -6041,17 +6014,14 @@ FROM [Officers] AS [o0] ) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] LEFT JOIN [Squads] AS [s] ON [t0].[SquadId] = [s].[Id] LEFT JOIN ( - SELECT [t4].[Nickname], [t4].[HasSoulPatch], [t4].[SquadId] - FROM ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[HasSoulPatch] - FROM [Gears] AS [g1] - UNION ALL - SELECT [o1].[Nickname], [o1].[SquadId], [o1].[HasSoulPatch] - FROM [Officers] AS [o1] - ) AS [t4] - ) AS [t1] ON [s].[Id] = [t1].[SquadId] -) AS [t3] ON [t].[FullName] = [t3].[OwnerFullName] -ORDER BY [t].[FullName], [t].[Nickname] DESC, [t].[SquadId], [t3].[Id], [t3].[Nickname], [t3].[SquadId], [t3].[Id0], [t3].[Nickname0]"); + SELECT [g1].[Nickname], [g1].[SquadId], [g1].[HasSoulPatch] + FROM [Gears] AS [g1] + UNION ALL + SELECT [o1].[Nickname], [o1].[SquadId], [o1].[HasSoulPatch] + FROM [Officers] AS [o1] + ) AS [t2] ON [s].[Id] = [t2].[SquadId] +) AS [t1] ON [t].[FullName] = [t1].[OwnerFullName] +ORDER BY [t].[FullName], [t].[Nickname] DESC, [t].[SquadId], [t1].[Id], [t1].[Nickname], [t1].[SquadId], [t1].[Id0], [t1].[Nickname0]"); } public override async Task Correlated_collections_with_funky_orderby_complex_scenario2(bool async) @@ -6059,44 +6029,41 @@ public override async Task Correlated_collections_with_funky_orderby_complex_sce await base.Correlated_collections_with_funky_orderby_complex_scenario2(async); AssertSql( - @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t5].[FullName], [t5].[Nickname], [t5].[SquadId], [t5].[Id], [t5].[Nickname0], [t5].[SquadId0], [t5].[Id0], [t5].[Nickname00], [t5].[HasSoulPatch], [t5].[SquadId00] + @"SELECT [t].[FullName], [t].[Nickname], [t].[SquadId], [t3].[FullName], [t3].[Nickname], [t3].[SquadId], [t3].[Id], [t3].[Nickname0], [t3].[SquadId0], [t3].[Id0], [t3].[Nickname00], [t3].[HasSoulPatch], [t3].[SquadId00] FROM ( SELECT [o].[Nickname], [o].[SquadId], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname] FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t3].[Id], [t3].[Nickname] AS [Nickname0], [t3].[SquadId] AS [SquadId0], [t3].[Id0], [t3].[Nickname0] AS [Nickname00], [t3].[HasSoulPatch], [t3].[SquadId0] AS [SquadId00], [t0].[HasSoulPatch] AS [HasSoulPatch0], [t3].[IsAutomatic], [t3].[Name], [t0].[LeaderNickname], [t0].[LeaderSquadId] + SELECT [t0].[FullName], [t0].[Nickname], [t0].[SquadId], [t1].[Id], [t1].[Nickname] AS [Nickname0], [t1].[SquadId] AS [SquadId0], [t1].[Id0], [t1].[Nickname0] AS [Nickname00], [t1].[HasSoulPatch], [t1].[SquadId0] AS [SquadId00], [t0].[HasSoulPatch] AS [HasSoulPatch0], [t1].[IsAutomatic], [t1].[Name], [t0].[LeaderNickname], [t0].[LeaderSquadId] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId] FROM [Officers] AS [o0] ) AS [t0] LEFT JOIN ( - SELECT [w].[Id], [t1].[Nickname], [t1].[SquadId], [s].[Id] AS [Id0], [t2].[Nickname] AS [Nickname0], [t2].[HasSoulPatch], [t2].[SquadId] AS [SquadId0], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName] + SELECT [w].[Id], [t2].[Nickname], [t2].[SquadId], [s].[Id] AS [Id0], [t4].[Nickname] AS [Nickname0], [t4].[HasSoulPatch], [t4].[SquadId] AS [SquadId0], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[FullName] - FROM [Gears] AS [g1] + SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] + FROM [Gears] AS [g0] UNION ALL SELECT [o1].[Nickname], [o1].[SquadId], [o1].[FullName] FROM [Officers] AS [o1] - ) AS [t1] ON [w].[OwnerFullName] = [t1].[FullName] - LEFT JOIN [Squads] AS [s] ON [t1].[SquadId] = [s].[Id] + ) AS [t2] ON [w].[OwnerFullName] = [t2].[FullName] + LEFT JOIN [Squads] AS [s] ON [t2].[SquadId] = [s].[Id] LEFT JOIN ( - SELECT [t6].[Nickname], [t6].[HasSoulPatch], [t6].[SquadId] - FROM ( - SELECT [g2].[Nickname], [g2].[SquadId], [g2].[HasSoulPatch] - FROM [Gears] AS [g2] - UNION ALL - SELECT [o2].[Nickname], [o2].[SquadId], [o2].[HasSoulPatch] - FROM [Officers] AS [o2] - ) AS [t6] - ) AS [t2] ON [s].[Id] = [t2].[SquadId] - ) AS [t3] ON [t0].[FullName] = [t3].[OwnerFullName] -) AS [t5] ON [t].[Nickname] = [t5].[LeaderNickname] AND [t].[SquadId] = [t5].[LeaderSquadId] -ORDER BY [t].[HasSoulPatch], [t].[LeaderNickname], [t].[FullName], [t].[Nickname], [t].[SquadId], [t5].[FullName], [t5].[HasSoulPatch0] DESC, [t5].[Nickname], [t5].[SquadId], [t5].[IsAutomatic], [t5].[Name] DESC, [t5].[Id], [t5].[Nickname0], [t5].[SquadId0], [t5].[Id0], [t5].[Nickname00]"); + SELECT [g1].[Nickname], [g1].[SquadId], [g1].[HasSoulPatch] + FROM [Gears] AS [g1] + UNION ALL + SELECT [o2].[Nickname], [o2].[SquadId], [o2].[HasSoulPatch] + FROM [Officers] AS [o2] + ) AS [t4] ON [s].[Id] = [t4].[SquadId] + ) AS [t1] ON [t0].[FullName] = [t1].[OwnerFullName] +) AS [t3] ON [t].[Nickname] = [t3].[LeaderNickname] AND [t].[SquadId] = [t3].[LeaderSquadId] +ORDER BY [t].[HasSoulPatch], [t].[LeaderNickname], [t].[FullName], [t].[Nickname], [t].[SquadId], [t3].[FullName], [t3].[HasSoulPatch0] DESC, [t3].[Nickname], [t3].[SquadId], [t3].[IsAutomatic], [t3].[Name] DESC, [t3].[Id], [t3].[Nickname0], [t3].[SquadId0], [t3].[Id0], [t3].[Nickname00]"); } public override async Task Correlated_collection_with_top_level_FirstOrDefault(bool async) @@ -6184,16 +6151,16 @@ public override async Task Null_semantics_on_nullable_bool_from_inner_join_subqu AssertSql( @"SELECT [t0].[Id], [t0].[CapitalName], [t0].[Name], [t0].[ServerAddress], [t0].[CommanderName], [t0].[Eradicated] FROM ( - SELECT [l].[Name] - FROM [LocustLeaders] AS [l] - UNION ALL SELECT [l0].[Name] - FROM [LocustCommanders] AS [l0] + FROM [LocustLeaders] AS [l0] + UNION ALL + SELECT [l1].[Name] + FROM [LocustCommanders] AS [l1] ) AS [t] INNER JOIN ( - SELECT [l1].[Id], [l1].[CapitalName], [l1].[Name], [l1].[ServerAddress], [l1].[CommanderName], [l1].[Eradicated] - FROM [LocustHordes] AS [l1] - WHERE [l1].[Name] = N'Swarm' + SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated] + FROM [LocustHordes] AS [l] + WHERE [l].[Name] = N'Swarm' ) AS [t0] ON [t].[Name] = [t0].[CommanderName] WHERE [t0].[Eradicated] <> CAST(1 AS bit) OR ([t0].[Eradicated] IS NULL)"); } @@ -6205,16 +6172,16 @@ public override async Task Null_semantics_on_nullable_bool_from_left_join_subque AssertSql( @"SELECT [t0].[Id], [t0].[CapitalName], [t0].[Name], [t0].[ServerAddress], [t0].[CommanderName], [t0].[Eradicated] FROM ( - SELECT [l].[Name] - FROM [LocustLeaders] AS [l] - UNION ALL SELECT [l0].[Name] - FROM [LocustCommanders] AS [l0] + FROM [LocustLeaders] AS [l0] + UNION ALL + SELECT [l1].[Name] + FROM [LocustCommanders] AS [l1] ) AS [t] LEFT JOIN ( - SELECT [l1].[Id], [l1].[CapitalName], [l1].[Name], [l1].[ServerAddress], [l1].[CommanderName], [l1].[Eradicated] - FROM [LocustHordes] AS [l1] - WHERE [l1].[Name] = N'Swarm' + SELECT [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated] + FROM [LocustHordes] AS [l] + WHERE [l].[Name] = N'Swarm' ) AS [t0] ON [t].[Name] = [t0].[CommanderName] WHERE [t0].[Eradicated] <> CAST(1 AS bit) OR ([t0].[Eradicated] IS NULL)"); } @@ -6226,9 +6193,9 @@ public override async Task Include_on_derived_type_with_order_by_and_paging(bool AssertSql( @"@__p_0='10' -SELECT [t3].[Name], [t3].[LocustHordeId], [t3].[ThreatLevel], [t3].[ThreatLevelByte], [t3].[ThreatLevelNullableByte], [t3].[DefeatedByNickname], [t3].[DefeatedBySquadId], [t3].[HighCommandId], [t3].[Discriminator], [t3].[Nickname], [t3].[SquadId], [t3].[AssignedCityName], [t3].[CityOfBirthName], [t3].[FullName], [t3].[HasSoulPatch], [t3].[LeaderNickname], [t3].[LeaderSquadId], [t3].[Rank], [t3].[Discriminator0] AS [Discriminator], [t3].[Id], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] +SELECT [t2].[Name], [t2].[LocustHordeId], [t2].[ThreatLevel], [t2].[ThreatLevelByte], [t2].[ThreatLevelNullableByte], [t2].[DefeatedByNickname], [t2].[DefeatedBySquadId], [t2].[HighCommandId], [t2].[Discriminator], [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator0] AS [Discriminator], [t2].[Id], [w].[Id], [w].[AmmunitionType], [w].[IsAutomatic], [w].[Name], [w].[OwnerFullName], [w].[SynergyWithId] FROM ( - SELECT TOP(@__p_0) [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] AS [Discriminator0], [t2].[Id], [t2].[Note] + SELECT TOP(@__p_0) [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] AS [Discriminator0], [t1].[Id], [t1].[Note] FROM ( SELECT [l].[Name], [l].[LocustHordeId], [l].[ThreatLevel], [l].[ThreatLevelByte], [l].[ThreatLevelNullableByte], NULL AS [DefeatedByNickname], NULL AS [DefeatedBySquadId], NULL AS [HighCommandId], N'LocustLeader' AS [Discriminator] FROM [LocustLeaders] AS [l] @@ -6243,11 +6210,11 @@ UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] ) AS [t0] ON [t].[DefeatedByNickname] = [t0].[Nickname] AND [t].[DefeatedBySquadId] = [t0].[SquadId] - LEFT JOIN [Tags] AS [t2] ON ([t0].[Nickname] = [t2].[GearNickName] OR ([t0].[Nickname] IS NULL AND [t2].[GearNickName] IS NULL)) AND ([t0].[SquadId] = [t2].[GearSquadId] OR ([t0].[SquadId] IS NULL AND [t2].[GearSquadId] IS NULL)) - ORDER BY [t2].[Note] -) AS [t3] -LEFT JOIN [Weapons] AS [w] ON [t3].[FullName] = [w].[OwnerFullName] -ORDER BY [t3].[Note], [t3].[Name], [t3].[Nickname], [t3].[SquadId], [t3].[Id]"); + LEFT JOIN [Tags] AS [t1] ON ([t0].[Nickname] = [t1].[GearNickName] OR ([t0].[Nickname] IS NULL AND [t1].[GearNickName] IS NULL)) AND ([t0].[SquadId] = [t1].[GearSquadId] OR ([t0].[SquadId] IS NULL AND [t1].[GearSquadId] IS NULL)) + ORDER BY [t1].[Note] +) AS [t2] +LEFT JOIN [Weapons] AS [w] ON [t2].[FullName] = [w].[OwnerFullName] +ORDER BY [t2].[Note], [t2].[Name], [t2].[Nickname], [t2].[SquadId], [t2].[Id]"); } public override async Task Select_required_navigation_on_derived_type(bool async) @@ -6255,15 +6222,15 @@ public override async Task Select_required_navigation_on_derived_type(bool async await base.Select_required_navigation_on_derived_type(async); AssertSql( - @"SELECT [l1].[Name] + @"SELECT [l].[Name] FROM ( SELECT NULL AS [HighCommandId] - FROM [LocustLeaders] AS [l] + FROM [LocustLeaders] AS [l0] UNION ALL - SELECT [l0].[HighCommandId] - FROM [LocustCommanders] AS [l0] + SELECT [l1].[HighCommandId] + FROM [LocustCommanders] AS [l1] ) AS [t] -LEFT JOIN [LocustHighCommands] AS [l1] ON [t].[HighCommandId] = [l1].[Id]"); +LEFT JOIN [LocustHighCommands] AS [l] ON [t].[HighCommandId] = [l].[Id]"); } public override async Task Select_required_navigation_on_the_same_type_with_cast(bool async) @@ -6289,14 +6256,14 @@ public override async Task Where_required_navigation_on_derived_type(bool async) AssertSql( @"SELECT [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator] FROM ( - SELECT [l].[Name], [l].[LocustHordeId], [l].[ThreatLevel], [l].[ThreatLevelByte], [l].[ThreatLevelNullableByte], NULL AS [DefeatedByNickname], NULL AS [DefeatedBySquadId], NULL AS [HighCommandId], N'LocustLeader' AS [Discriminator] - FROM [LocustLeaders] AS [l] + SELECT [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], NULL AS [DefeatedByNickname], NULL AS [DefeatedBySquadId], NULL AS [HighCommandId], N'LocustLeader' AS [Discriminator] + FROM [LocustLeaders] AS [l0] UNION ALL - SELECT [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], N'LocustCommander' AS [Discriminator] - FROM [LocustCommanders] AS [l0] + SELECT [l1].[Name], [l1].[LocustHordeId], [l1].[ThreatLevel], [l1].[ThreatLevelByte], [l1].[ThreatLevelNullableByte], [l1].[DefeatedByNickname], [l1].[DefeatedBySquadId], [l1].[HighCommandId], N'LocustCommander' AS [Discriminator] + FROM [LocustCommanders] AS [l1] ) AS [t] -LEFT JOIN [LocustHighCommands] AS [l1] ON [t].[HighCommandId] = [l1].[Id] -WHERE [l1].[IsOperational] = CAST(1 AS bit)"); +LEFT JOIN [LocustHighCommands] AS [l] ON [t].[HighCommandId] = [l].[Id] +WHERE [l].[IsOperational] = CAST(1 AS bit)"); } public override async Task Outer_parameter_in_join_key(bool async) @@ -6304,23 +6271,23 @@ public override async Task Outer_parameter_in_join_key(bool async) await base.Outer_parameter_in_join_key(async); AssertSql( - @"SELECT [t].[Nickname], [t].[SquadId], [t2].[Note], [t2].[Id], [t2].[Nickname], [t2].[SquadId] + @"SELECT [t].[Nickname], [t].[SquadId], [t1].[Note], [t1].[Id], [t1].[Nickname], [t1].[SquadId] FROM ( SELECT [o].[Nickname], [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] ) AS [t] OUTER APPLY ( - SELECT [t0].[Note], [t0].[Id], [t1].[Nickname], [t1].[SquadId] + SELECT [t0].[Note], [t0].[Id], [t2].[Nickname], [t2].[SquadId] FROM [Tags] AS [t0] INNER JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName] FROM [Officers] AS [o0] - ) AS [t1] ON [t].[FullName] = [t1].[FullName] -) AS [t2] -ORDER BY [t].[Nickname], [t].[SquadId], [t2].[Id], [t2].[Nickname]"); + ) AS [t2] ON [t].[FullName] = [t2].[FullName] +) AS [t1] +ORDER BY [t].[Nickname], [t].[SquadId], [t1].[Id], [t1].[Nickname]"); } public override async Task Outer_parameter_in_join_key_inner_and_outer(bool async) @@ -6328,23 +6295,23 @@ public override async Task Outer_parameter_in_join_key_inner_and_outer(bool asyn await base.Outer_parameter_in_join_key_inner_and_outer(async); AssertSql( - @"SELECT [t].[Nickname], [t].[SquadId], [t2].[Note], [t2].[Id], [t2].[Nickname], [t2].[SquadId] + @"SELECT [t].[Nickname], [t].[SquadId], [t1].[Note], [t1].[Id], [t1].[Nickname], [t1].[SquadId] FROM ( SELECT [o].[Nickname], [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] ) AS [t] OUTER APPLY ( - SELECT [t0].[Note], [t0].[Id], [t1].[Nickname], [t1].[SquadId] + SELECT [t0].[Note], [t0].[Id], [t2].[Nickname], [t2].[SquadId] FROM [Tags] AS [t0] INNER JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId] FROM [Officers] AS [o0] - ) AS [t1] ON [t].[FullName] = [t].[Nickname] -) AS [t2] -ORDER BY [t].[Nickname], [t].[SquadId], [t2].[Id], [t2].[Nickname]"); + ) AS [t2] ON [t].[FullName] = [t].[Nickname] +) AS [t1] +ORDER BY [t].[Nickname], [t].[SquadId], [t1].[Id], [t1].[Nickname]"); } public override async Task Outer_parameter_in_group_join_with_DefaultIfEmpty(bool async) @@ -6352,23 +6319,23 @@ public override async Task Outer_parameter_in_group_join_with_DefaultIfEmpty(boo await base.Outer_parameter_in_group_join_with_DefaultIfEmpty(async); AssertSql( - @"SELECT [t].[Nickname], [t].[SquadId], [t2].[Note], [t2].[Id], [t2].[Nickname], [t2].[SquadId] + @"SELECT [t].[Nickname], [t].[SquadId], [t1].[Note], [t1].[Id], [t1].[Nickname], [t1].[SquadId] FROM ( SELECT [o].[Nickname], [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] ) AS [t] OUTER APPLY ( - SELECT [t0].[Note], [t0].[Id], [t1].[Nickname], [t1].[SquadId] + SELECT [t0].[Note], [t0].[Id], [t2].[Nickname], [t2].[SquadId] FROM [Tags] AS [t0] LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName] FROM [Officers] AS [o0] - ) AS [t1] ON [t].[FullName] = [t1].[FullName] -) AS [t2] -ORDER BY [t].[Nickname], [t].[SquadId], [t2].[Id], [t2].[Nickname]"); + ) AS [t2] ON [t].[FullName] = [t2].[FullName] +) AS [t1] +ORDER BY [t].[Nickname], [t].[SquadId], [t1].[Id], [t1].[Nickname]"); } public override async Task Negated_bool_ternary_inside_anonymous_type_in_projection(bool async) @@ -6420,8 +6387,8 @@ public override async Task Order_by_entity_qsre_with_inheritance(bool async) SELECT [l0].[Name], [l0].[HighCommandId] FROM [LocustCommanders] AS [l0] ) AS [t] -INNER JOIN [LocustHighCommands] AS [l1] ON [t].[HighCommandId] = [l1].[Id] -ORDER BY [l1].[Id], [t].[Name]"); +INNER JOIN [LocustHighCommands] AS [l] ON [t].[HighCommandId] = [l].[Id] +ORDER BY [l].[Id], [t].[Name]"); } public override async Task Order_by_entity_qsre_composite_key(bool async) @@ -6437,8 +6404,8 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] -) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] -ORDER BY [t0].[Nickname], [t0].[SquadId], [w].[Id]"); +) AS [t] ON [w].[OwnerFullName] = [t].[FullName] +ORDER BY [t].[Nickname], [t].[SquadId], [w].[Id]"); } public override async Task Order_by_entity_qsre_with_other_orderbys(bool async) @@ -6454,9 +6421,9 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] -) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] +) AS [t] ON [w].[OwnerFullName] = [t].[FullName] LEFT JOIN [Weapons] AS [w0] ON [w].[SynergyWithId] = [w0].[Id] -ORDER BY [w].[IsAutomatic], [t0].[Nickname] DESC, [t0].[SquadId] DESC, [w0].[Id], [w].[Name]"); +ORDER BY [w].[IsAutomatic], [t].[Nickname] DESC, [t].[SquadId] DESC, [w0].[Id], [w].[Name]"); } public override async Task Join_on_entity_qsre_keys(bool async) @@ -6546,7 +6513,7 @@ public override async Task Join_on_entity_qsre_keys_inner_key_is_navigation_comp await base.Join_on_entity_qsre_keys_inner_key_is_navigation_composite_key(async); AssertSql( - @"SELECT [t].[Nickname], [t2].[Note] + @"SELECT [t].[Nickname], [t1].[Note] FROM ( SELECT [g].[Nickname], [g].[SquadId] FROM [Gears] AS [g] @@ -6555,7 +6522,7 @@ UNION ALL FROM [Officers] AS [o] ) AS [t] INNER JOIN ( - SELECT [t0].[Note], [t1].[Nickname], [t1].[SquadId] + SELECT [t0].[Note], [t2].[Nickname], [t2].[SquadId] FROM [Tags] AS [t0] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId] @@ -6563,9 +6530,9 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId] FROM [Officers] AS [o0] - ) AS [t1] ON [t0].[GearNickName] = [t1].[Nickname] AND [t0].[GearSquadId] = [t1].[SquadId] + ) AS [t2] ON [t0].[GearNickName] = [t2].[Nickname] AND [t0].[GearSquadId] = [t2].[SquadId] WHERE [t0].[Note] IN (N'Cole''s Tag', N'Dom''s Tag') -) AS [t2] ON [t].[Nickname] = [t2].[Nickname] AND [t].[SquadId] = [t2].[SquadId]"); +) AS [t1] ON [t].[Nickname] = [t1].[Nickname] AND [t].[SquadId] = [t1].[SquadId]"); } public override async Task Join_on_entity_qsre_keys_inner_key_is_nested_navigation(bool async) @@ -6573,7 +6540,7 @@ public override async Task Join_on_entity_qsre_keys_inner_key_is_nested_navigati await base.Join_on_entity_qsre_keys_inner_key_is_nested_navigation(async); AssertSql( - @"SELECT [s].[Name] AS [SquadName], [t1].[Name] AS [WeaponName] + @"SELECT [s].[Name] AS [SquadName], [t0].[Name] AS [WeaponName] FROM [Squads] AS [s] INNER JOIN ( SELECT [w].[Name], [s0].[Id] AS [Id0] @@ -6584,10 +6551,10 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] - ) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] - LEFT JOIN [Squads] AS [s0] ON [t0].[SquadId] = [s0].[Id] + ) AS [t] ON [w].[OwnerFullName] = [t].[FullName] + LEFT JOIN [Squads] AS [s0] ON [t].[SquadId] = [s0].[Id] WHERE [w].[IsAutomatic] = CAST(1 AS bit) -) AS [t1] ON [s].[Id] = [t1].[Id0]"); +) AS [t0] ON [s].[Id] = [t0].[Id0]"); } public override async Task GroupJoin_on_entity_qsre_keys_inner_key_is_nested_navigation(bool async) @@ -6595,7 +6562,7 @@ public override async Task GroupJoin_on_entity_qsre_keys_inner_key_is_nested_nav await base.GroupJoin_on_entity_qsre_keys_inner_key_is_nested_navigation(async); AssertSql( - @"SELECT [s].[Name] AS [SquadName], [t1].[Name] AS [WeaponName] + @"SELECT [s].[Name] AS [SquadName], [t0].[Name] AS [WeaponName] FROM [Squads] AS [s] LEFT JOIN ( SELECT [w].[Name], [s0].[Id] AS [Id0] @@ -6606,9 +6573,9 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[SquadId], [o].[FullName] FROM [Officers] AS [o] - ) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] - LEFT JOIN [Squads] AS [s0] ON [t0].[SquadId] = [s0].[Id] -) AS [t1] ON [s].[Id] = [t1].[Id0]"); + ) AS [t] ON [w].[OwnerFullName] = [t].[FullName] + LEFT JOIN [Squads] AS [s0] ON [t].[SquadId] = [s0].[Id] +) AS [t0] ON [s].[Id] = [t0].[Id0]"); } public override async Task Streaming_correlated_collection_issue_11403(bool async) @@ -6825,7 +6792,7 @@ public override async Task Include_with_order_by_constant(bool async) await base.Include_with_order_by_constant(async); AssertSql( - @"SELECT [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator] + @"SELECT [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name], [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator] FROM [Squads] AS [s] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] @@ -6833,8 +6800,8 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] -) AS [t0] ON [s].[Id] = [t0].[SquadId] -ORDER BY [s].[Id], [t0].[Nickname]"); +) AS [t] ON [s].[Id] = [t].[SquadId] +ORDER BY [s].[Id], [t].[Nickname]"); } public override async Task Correlated_collection_order_by_constant(bool async) @@ -6913,8 +6880,8 @@ public override async Task Include_collection_OrderBy_aggregate(bool async) FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] @@ -6936,8 +6903,8 @@ public override async Task Include_collection_with_complex_OrderBy2(bool async) FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] @@ -6960,8 +6927,8 @@ public override async Task Include_collection_with_complex_OrderBy3(bool async) FROM [Officers] AS [o] ) AS [t] LEFT JOIN ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] @@ -6986,8 +6953,8 @@ FROM [Officers] AS [o] LEFT JOIN ( SELECT [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] @@ -7013,11 +6980,11 @@ FROM [Officers] AS [o] LEFT JOIN ( SELECT [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator] FROM ( - SELECT [g1].[Nickname], [g1].[SquadId], [g1].[AssignedCityName], [g1].[CityOfBirthName], [g1].[FullName], [g1].[HasSoulPatch], [g1].[LeaderNickname], [g1].[LeaderSquadId], [g1].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g1] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] UNION ALL - SELECT [o1].[Nickname], [o1].[SquadId], [o1].[AssignedCityName], [o1].[CityOfBirthName], [o1].[FullName], [o1].[HasSoulPatch], [o1].[LeaderNickname], [o1].[LeaderSquadId], [o1].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o1] + SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] + FROM [Officers] AS [o0] ) AS [t2] WHERE [t2].[HasSoulPatch] = CAST(0 AS bit) ) AS [t1] ON [t].[Nickname] = [t1].[LeaderNickname] AND [t].[SquadId] = [t1].[LeaderSquadId] @@ -7030,8 +6997,8 @@ SELECT TOP(1) [t0].[HasSoulPatch] SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g0] UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] - FROM [Officers] AS [o0] + SELECT [o1].[Nickname], [o1].[SquadId], [o1].[AssignedCityName], [o1].[CityOfBirthName], [o1].[FullName], [o1].[HasSoulPatch], [o1].[LeaderNickname], [o1].[LeaderSquadId], [o1].[Rank], N'Officer' AS [Discriminator] + FROM [Officers] AS [o1] ) AS [t0] WHERE [t0].[Nickname] = N'Marcus'), CAST(0 AS bit))), [t].[Nickname], [t].[SquadId], [t1].[Nickname]"); } @@ -7332,20 +7299,17 @@ public override async Task Cast_subquery_to_base_type_using_typed_ToList(bool as await base.Cast_subquery_to_base_type_using_typed_ToList(async); AssertSql( - @"SELECT [c].[Name], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Nickname], [t0].[Rank], [t0].[SquadId] + @"SELECT [c].[Name], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Nickname], [t].[Rank], [t].[SquadId] FROM [Cities] AS [c] LEFT JOIN ( - SELECT [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Nickname], [t].[Rank], [t].[SquadId], [t].[AssignedCityName] - FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] - FROM [Gears] AS [g] - UNION ALL - SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank] - FROM [Officers] AS [o] - ) AS [t] -) AS [t0] ON [c].[Name] = [t0].[AssignedCityName] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] + FROM [Gears] AS [g] + UNION ALL + SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank] + FROM [Officers] AS [o] +) AS [t] ON [c].[Name] = [t].[AssignedCityName] WHERE [c].[Name] = N'Ephyra' -ORDER BY [c].[Name], [t0].[Nickname]"); +ORDER BY [c].[Name], [t].[Nickname]"); } public override async Task Cast_ordered_subquery_to_base_type_using_typed_ToArray(bool async) @@ -7353,20 +7317,17 @@ public override async Task Cast_ordered_subquery_to_base_type_using_typed_ToArra await base.Cast_ordered_subquery_to_base_type_using_typed_ToArray(async); AssertSql( - @"SELECT [c].[Name], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Nickname], [t0].[Rank], [t0].[SquadId] + @"SELECT [c].[Name], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Nickname], [t].[Rank], [t].[SquadId] FROM [Cities] AS [c] LEFT JOIN ( - SELECT [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Nickname], [t].[Rank], [t].[SquadId], [t].[AssignedCityName] - FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] - FROM [Gears] AS [g] - UNION ALL - SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank] - FROM [Officers] AS [o] - ) AS [t] -) AS [t0] ON [c].[Name] = [t0].[AssignedCityName] + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank] + FROM [Gears] AS [g] + UNION ALL + SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank] + FROM [Officers] AS [o] +) AS [t] ON [c].[Name] = [t].[AssignedCityName] WHERE [c].[Name] = N'Ephyra' -ORDER BY [c].[Name], [t0].[Nickname] DESC"); +ORDER BY [c].[Name], [t].[Nickname] DESC"); } public override async Task Correlated_collection_with_complex_order_by_funcletized_to_constant_bool(bool async) @@ -8233,7 +8194,7 @@ public override async Task Project_collection_navigation_nested_with_take_compos await base.Project_collection_navigation_nested_with_take_composite_key(async); AssertSql( - @"SELECT [t].[Id], [t0].[Nickname], [t0].[SquadId], [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator] + @"SELECT [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], N'Gear' AS [Discriminator] @@ -8243,21 +8204,21 @@ UNION ALL FROM [Officers] AS [o] ) AS [t0] ON [t].[GearNickName] = [t0].[Nickname] AND [t].[GearSquadId] = [t0].[SquadId] LEFT JOIN ( - SELECT [t3].[Nickname], [t3].[SquadId], [t3].[AssignedCityName], [t3].[CityOfBirthName], [t3].[FullName], [t3].[HasSoulPatch], [t3].[LeaderNickname], [t3].[LeaderSquadId], [t3].[Rank], [t3].[Discriminator] + SELECT [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator] FROM ( - SELECT [t4].[Nickname], [t4].[SquadId], [t4].[AssignedCityName], [t4].[CityOfBirthName], [t4].[FullName], [t4].[HasSoulPatch], [t4].[LeaderNickname], [t4].[LeaderSquadId], [t4].[Rank], [t4].[Discriminator], ROW_NUMBER() OVER(PARTITION BY [t4].[LeaderNickname], [t4].[LeaderSquadId] ORDER BY [t4].[Nickname], [t4].[SquadId]) AS [row] + SELECT [t3].[Nickname], [t3].[SquadId], [t3].[AssignedCityName], [t3].[CityOfBirthName], [t3].[FullName], [t3].[HasSoulPatch], [t3].[LeaderNickname], [t3].[LeaderSquadId], [t3].[Rank], [t3].[Discriminator], ROW_NUMBER() OVER(PARTITION BY [t3].[LeaderNickname], [t3].[LeaderSquadId] ORDER BY [t3].[Nickname], [t3].[SquadId]) AS [row] FROM ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] - ) AS [t4] - ) AS [t3] - WHERE [t3].[row] <= 50 -) AS [t2] ON ([t0].[Nickname] = [t2].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t2].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t2].[LeaderSquadId] + ) AS [t3] + ) AS [t2] + WHERE [t2].[row] <= 50 +) AS [t1] ON ([t0].[Nickname] = [t1].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t1].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t1].[LeaderSquadId] WHERE [t0].[Discriminator] = N'Officer' -ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t2].[Nickname]"); +ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname]"); } public override async Task Project_collection_navigation_nested_composite_key(bool async) @@ -8265,7 +8226,7 @@ public override async Task Project_collection_navigation_nested_composite_key(bo await base.Project_collection_navigation_nested_composite_key(async); AssertSql( - @"SELECT [t].[Id], [t0].[Nickname], [t0].[SquadId], [t2].[Nickname], [t2].[SquadId], [t2].[AssignedCityName], [t2].[CityOfBirthName], [t2].[FullName], [t2].[HasSoulPatch], [t2].[LeaderNickname], [t2].[LeaderSquadId], [t2].[Rank], [t2].[Discriminator] + @"SELECT [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname], [t1].[SquadId], [t1].[AssignedCityName], [t1].[CityOfBirthName], [t1].[FullName], [t1].[HasSoulPatch], [t1].[LeaderNickname], [t1].[LeaderSquadId], [t1].[Rank], [t1].[Discriminator] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], N'Gear' AS [Discriminator] @@ -8280,9 +8241,9 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o0] -) AS [t2] ON ([t0].[Nickname] = [t2].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t2].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t2].[LeaderSquadId] +) AS [t1] ON ([t0].[Nickname] = [t1].[LeaderNickname] OR ([t0].[Nickname] IS NULL AND [t1].[LeaderNickname] IS NULL)) AND [t0].[SquadId] = [t1].[LeaderSquadId] WHERE [t0].[Discriminator] = N'Officer' -ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t2].[Nickname]"); +ORDER BY [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname]"); } public override async Task Null_checks_in_correlated_predicate_are_correctly_translated(bool async) @@ -8408,13 +8369,13 @@ public override async Task Navigation_based_on_complex_expression4(bool async) await base.Navigation_based_on_complex_expression4(async); AssertSql( - @"SELECT CAST(1 AS bit), [l2].[Name], [l2].[LocustHordeId], [l2].[ThreatLevel], [l2].[ThreatLevelByte], [l2].[ThreatLevelNullableByte], [l2].[DefeatedByNickname], [l2].[DefeatedBySquadId], [l2].[HighCommandId], [t0].[Name], [t0].[LocustHordeId], [t0].[ThreatLevel], [t0].[ThreatLevelByte], [t0].[ThreatLevelNullableByte], [t0].[DefeatedByNickname], [t0].[DefeatedBySquadId], [t0].[HighCommandId], [t0].[Discriminator] + @"SELECT CAST(1 AS bit), [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator] FROM [LocustHordes] AS [l] CROSS JOIN ( SELECT [l1].[Name], [l1].[LocustHordeId], [l1].[ThreatLevel], [l1].[ThreatLevelByte], [l1].[ThreatLevelNullableByte], [l1].[DefeatedByNickname], [l1].[DefeatedBySquadId], [l1].[HighCommandId], N'LocustCommander' AS [Discriminator] FROM [LocustCommanders] AS [l1] -) AS [t0] -LEFT JOIN [LocustCommanders] AS [l2] ON [l].[CommanderName] = [l2].[Name]"); +) AS [t] +LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name]"); } public override async Task Navigation_based_on_complex_expression5(bool async) @@ -8422,13 +8383,13 @@ public override async Task Navigation_based_on_complex_expression5(bool async) await base.Navigation_based_on_complex_expression5(async); AssertSql( - @"SELECT [l2].[Name], [l2].[LocustHordeId], [l2].[ThreatLevel], [l2].[ThreatLevelByte], [l2].[ThreatLevelNullableByte], [l2].[DefeatedByNickname], [l2].[DefeatedBySquadId], [l2].[HighCommandId], [t0].[Name], [t0].[LocustHordeId], [t0].[ThreatLevel], [t0].[ThreatLevelByte], [t0].[ThreatLevelNullableByte], [t0].[DefeatedByNickname], [t0].[DefeatedBySquadId], [t0].[HighCommandId], [t0].[Discriminator] + @"SELECT [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator] FROM [LocustHordes] AS [l] CROSS JOIN ( SELECT [l1].[Name], [l1].[LocustHordeId], [l1].[ThreatLevel], [l1].[ThreatLevelByte], [l1].[ThreatLevelNullableByte], [l1].[DefeatedByNickname], [l1].[DefeatedBySquadId], [l1].[HighCommandId], N'LocustCommander' AS [Discriminator] FROM [LocustCommanders] AS [l1] -) AS [t0] -LEFT JOIN [LocustCommanders] AS [l2] ON [l].[CommanderName] = [l2].[Name]"); +) AS [t] +LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name]"); } public override async Task Navigation_based_on_complex_expression6(bool async) @@ -8437,15 +8398,15 @@ public override async Task Navigation_based_on_complex_expression6(bool async) AssertSql( @"SELECT CASE - WHEN [l2].[Name] = N'Queen Myrrah' AND [l2].[Name] IS NOT NULL THEN CAST(1 AS bit) + WHEN [l0].[Name] = N'Queen Myrrah' AND [l0].[Name] IS NOT NULL THEN CAST(1 AS bit) ELSE CAST(0 AS bit) -END, [l2].[Name], [l2].[LocustHordeId], [l2].[ThreatLevel], [l2].[ThreatLevelByte], [l2].[ThreatLevelNullableByte], [l2].[DefeatedByNickname], [l2].[DefeatedBySquadId], [l2].[HighCommandId], [t0].[Name], [t0].[LocustHordeId], [t0].[ThreatLevel], [t0].[ThreatLevelByte], [t0].[ThreatLevelNullableByte], [t0].[DefeatedByNickname], [t0].[DefeatedBySquadId], [t0].[HighCommandId], [t0].[Discriminator] +END, [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator] FROM [LocustHordes] AS [l] CROSS JOIN ( SELECT [l1].[Name], [l1].[LocustHordeId], [l1].[ThreatLevel], [l1].[ThreatLevelByte], [l1].[ThreatLevelNullableByte], [l1].[DefeatedByNickname], [l1].[DefeatedBySquadId], [l1].[HighCommandId], N'LocustCommander' AS [Discriminator] FROM [LocustCommanders] AS [l1] -) AS [t0] -LEFT JOIN [LocustCommanders] AS [l2] ON [l].[CommanderName] = [l2].[Name]"); +) AS [t] +LEFT JOIN [LocustCommanders] AS [l0] ON [l].[CommanderName] = [l0].[Name]"); } public override async Task Select_as_operator(bool async) @@ -8548,7 +8509,7 @@ public override async Task Accessing_property_of_optional_navigation_in_child_pr @"SELECT CASE WHEN [t0].[Nickname] IS NOT NULL AND [t0].[SquadId] IS NOT NULL THEN CAST(1 AS bit) ELSE CAST(0 AS bit) -END, [t].[Id], [t0].[Nickname], [t0].[SquadId], [t2].[Nickname], [t2].[Id], [t2].[SquadId] +END, [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[Nickname], [t1].[Id], [t1].[SquadId] FROM [Tags] AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] @@ -8558,7 +8519,7 @@ UNION ALL FROM [Officers] AS [o] ) AS [t0] ON [t].[GearNickName] = [t0].[Nickname] AND [t].[GearSquadId] = [t0].[SquadId] LEFT JOIN ( - SELECT [t3].[Nickname], [w].[Id], [t3].[SquadId], [w].[OwnerFullName] + SELECT [t2].[Nickname], [w].[Id], [t2].[SquadId], [w].[OwnerFullName] FROM [Weapons] AS [w] LEFT JOIN ( SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName] @@ -8566,9 +8527,9 @@ FROM [Gears] AS [g0] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName] FROM [Officers] AS [o0] - ) AS [t3] ON [w].[OwnerFullName] = [t3].[FullName] -) AS [t2] ON [t0].[FullName] = [t2].[OwnerFullName] -ORDER BY [t].[Note], [t].[Id], [t0].[Nickname], [t0].[SquadId], [t2].[Id], [t2].[Nickname]"); + ) AS [t2] ON [w].[OwnerFullName] = [t2].[FullName] +) AS [t1] ON [t0].[FullName] = [t1].[OwnerFullName] +ORDER BY [t].[Note], [t].[Id], [t0].[Nickname], [t0].[SquadId], [t1].[Id], [t1].[Nickname]"); } public override async Task Collection_navigation_ofType_filter_works(bool async) @@ -8581,9 +8542,6 @@ FROM [Cities] AS [c] WHERE EXISTS ( SELECT 1 FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] - FROM [Gears] AS [g] - UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] ) AS [t] @@ -8710,10 +8668,10 @@ SELECT COUNT(*) FROM [Weapons] AS [w] WHERE [t].[FullName] = [w].[OwnerFullName]) AS [Count] FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + SELECT [g].[AssignedCityName], [g].[FullName] FROM [Gears] AS [g] UNION ALL - SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] + SELECT [o].[AssignedCityName], [o].[FullName] FROM [Officers] AS [o] ) AS [t] LEFT JOIN [Cities] AS [c] ON [t].[AssignedCityName] = [c].[Name] @@ -8723,10 +8681,10 @@ SELECT COUNT(*) FROM [Weapons] AS [w0] WHERE [t1].[FullName] = [w0].[OwnerFullName]) AS [Count] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] + SELECT [g0].[CityOfBirthName], [g0].[FullName] FROM [Gears] AS [g0] UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] + SELECT [o0].[CityOfBirthName], [o0].[FullName] FROM [Officers] AS [o0] ) AS [t1] INNER JOIN [Cities] AS [c0] ON [t1].[CityOfBirthName] = [c0].[Name] @@ -8746,10 +8704,10 @@ SELECT COUNT(*) FROM [Weapons] AS [w] WHERE [t].[FullName] = [w].[OwnerFullName]) AS [Count] FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + SELECT [g].[AssignedCityName], [g].[FullName] FROM [Gears] AS [g] UNION ALL - SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] + SELECT [o].[AssignedCityName], [o].[FullName] FROM [Officers] AS [o] ) AS [t] LEFT JOIN [Cities] AS [c] ON [t].[AssignedCityName] = [c].[Name] @@ -8759,10 +8717,10 @@ SELECT COUNT(*) FROM [Weapons] AS [w0] WHERE [t1].[FullName] = [w0].[OwnerFullName]) AS [Count] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], N'Gear' AS [Discriminator] + SELECT [g0].[CityOfBirthName], [g0].[FullName] FROM [Gears] AS [g0] UNION ALL - SELECT [o0].[Nickname], [o0].[SquadId], [o0].[AssignedCityName], [o0].[CityOfBirthName], [o0].[FullName], [o0].[HasSoulPatch], [o0].[LeaderNickname], [o0].[LeaderSquadId], [o0].[Rank], N'Officer' AS [Discriminator] + SELECT [o0].[CityOfBirthName], [o0].[FullName] FROM [Officers] AS [o0] ) AS [t1] INNER JOIN [Cities] AS [c0] ON [t1].[CityOfBirthName] = [c0].[Name] @@ -8978,14 +8936,17 @@ UNION ALL FROM [Officers] AS [o] ) AS [t] WHERE ([t].[Rank] & @__rank_0) = @__rank_0", - // - @"SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] -FROM [Gears] AS [g] -UNION ALL -SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] -FROM [Officers] AS [o]", - // - @"@__rank_0='2' (Nullable = true) + // + @"SELECT [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator] +FROM ( + SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] + FROM [Gears] AS [g] + UNION ALL + SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] + FROM [Officers] AS [o] +) AS [t]", + // + @"@__rank_0='2' (Nullable = true) SELECT [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator] FROM ( @@ -8996,8 +8957,8 @@ UNION ALL FROM [Officers] AS [o] ) AS [t] WHERE ([t].[Rank] | @__rank_0) <> @__rank_0", - // - @"SELECT [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator] + // + @"SELECT [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator] FROM ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] FROM [Gears] AS [g] @@ -9163,22 +9124,22 @@ public override async Task Join_inner_source_custom_projection_followed_by_filte AssertSql( @"SELECT CASE - WHEN [l1].[Name] = N'Locust' THEN CAST(1 AS bit) + WHEN [l].[Name] = N'Locust' THEN CAST(1 AS bit) ELSE NULL -END AS [IsEradicated], [l1].[CommanderName], [l1].[Name] +END AS [IsEradicated], [l].[CommanderName], [l].[Name] FROM ( - SELECT [l].[Name] - FROM [LocustLeaders] AS [l] - UNION ALL SELECT [l0].[Name] - FROM [LocustCommanders] AS [l0] + FROM [LocustLeaders] AS [l0] + UNION ALL + SELECT [l1].[Name] + FROM [LocustCommanders] AS [l1] ) AS [t] -INNER JOIN [LocustHordes] AS [l1] ON [t].[Name] = [l1].[CommanderName] +INNER JOIN [LocustHordes] AS [l] ON [t].[Name] = [l].[CommanderName] WHERE CASE - WHEN [l1].[Name] = N'Locust' THEN CAST(1 AS bit) + WHEN [l].[Name] = N'Locust' THEN CAST(1 AS bit) ELSE NULL END <> CAST(1 AS bit) OR (CASE - WHEN [l1].[Name] = N'Locust' THEN CAST(1 AS bit) + WHEN [l].[Name] = N'Locust' THEN CAST(1 AS bit) ELSE NULL END IS NULL)"); } @@ -9623,7 +9584,7 @@ public override async Task Contains_on_byte_array_property_using_byte_column(boo await base.Contains_on_byte_array_property_using_byte_column(async); AssertSql( - @"SELECT [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name], [t0].[Name], [t0].[LocustHordeId], [t0].[ThreatLevel], [t0].[ThreatLevelByte], [t0].[ThreatLevelNullableByte], [t0].[DefeatedByNickname], [t0].[DefeatedBySquadId], [t0].[HighCommandId], [t0].[Discriminator] + @"SELECT [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name], [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator] FROM [Squads] AS [s] CROSS JOIN ( SELECT [l].[Name], [l].[LocustHordeId], [l].[ThreatLevel], [l].[ThreatLevelByte], [l].[ThreatLevelNullableByte], NULL AS [DefeatedByNickname], NULL AS [DefeatedBySquadId], NULL AS [HighCommandId], N'LocustLeader' AS [Discriminator] @@ -9631,8 +9592,8 @@ FROM [LocustLeaders] AS [l] UNION ALL SELECT [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], N'LocustCommander' AS [Discriminator] FROM [LocustCommanders] AS [l0] -) AS [t0] -WHERE CHARINDEX(CAST([t0].[ThreatLevelByte] AS varbinary(max)), [s].[Banner]) > 0"); +) AS [t] +WHERE CHARINDEX(CAST([t].[ThreatLevelByte] AS varbinary(max)), [s].[Banner]) > 0"); } public override async Task Subquery_projecting_non_nullable_scalar_contains_non_nullable_value_doesnt_need_null_expansion( @@ -9900,8 +9861,8 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[CityOfBirthName], [o].[FullName] FROM [Officers] AS [o] -) AS [t0] ON [w].[OwnerFullName] = [t0].[FullName] -LEFT JOIN [Cities] AS [c] ON [t0].[CityOfBirthName] = [c].[Name] +) AS [t] ON [w].[OwnerFullName] = [t].[FullName] +LEFT JOIN [Cities] AS [c] ON [t].[CityOfBirthName] = [c].[Name] GROUP BY [c].[Name], [c].[Location] ORDER BY [c].[Location]"); } @@ -10083,8 +10044,8 @@ FROM [Officers] AS [o] OUTER APPLY ( SELECT [t1].[FullName] AS [ReportName], [t].[FullName] AS [OfficerName], [t1].[Nickname], [t1].[SquadId] FROM ( - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[FullName], [g0].[LeaderNickname], [g0].[LeaderSquadId] - FROM [Gears] AS [g0] + SELECT [g].[Nickname], [g].[SquadId], [g].[FullName], [g].[LeaderNickname], [g].[LeaderSquadId] + FROM [Gears] AS [g] UNION ALL SELECT [o0].[Nickname], [o0].[SquadId], [o0].[FullName], [o0].[LeaderNickname], [o0].[LeaderSquadId] FROM [Officers] AS [o0] @@ -10253,8 +10214,8 @@ public override async Task Composite_key_entity_equal_null(bool async) AssertSql( @"SELECT [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator] FROM ( - SELECT [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], N'LocustCommander' AS [Discriminator] - FROM [LocustCommanders] AS [l0] + SELECT [l].[Name], [l].[LocustHordeId], [l].[ThreatLevel], [l].[ThreatLevelByte], [l].[ThreatLevelNullableByte], [l].[DefeatedByNickname], [l].[DefeatedBySquadId], [l].[HighCommandId], N'LocustCommander' AS [Discriminator] + FROM [LocustCommanders] AS [l] ) AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId] @@ -10273,8 +10234,8 @@ public override async Task Composite_key_entity_not_equal_null(bool async) AssertSql( @"SELECT [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator] FROM ( - SELECT [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], N'LocustCommander' AS [Discriminator] - FROM [LocustCommanders] AS [l0] + SELECT [l].[Name], [l].[LocustHordeId], [l].[ThreatLevel], [l].[ThreatLevelByte], [l].[ThreatLevelNullableByte], [l].[DefeatedByNickname], [l].[DefeatedBySquadId], [l].[HighCommandId], N'LocustCommander' AS [Discriminator] + FROM [LocustCommanders] AS [l] ) AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId] @@ -10743,19 +10704,19 @@ public override async Task Project_navigation_defined_on_derived_from_entity_wit @"SELECT [t].[Name], [t].[LocustHordeId], [t].[ThreatLevel], [t].[ThreatLevelByte], [t].[ThreatLevelNullableByte], [t].[DefeatedByNickname], [t].[DefeatedBySquadId], [t].[HighCommandId], [t].[Discriminator], [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], CASE WHEN [t0].[Nickname] IS NULL OR [t0].[SquadId] IS NULL THEN CAST(1 AS bit) ELSE CAST(0 AS bit) -END AS [IsNull], [l1].[Id], [l1].[CapitalName], [l1].[Name], [l1].[ServerAddress], [l1].[CommanderName], [l1].[Eradicated], CASE - WHEN [l1].[Id] IS NULL THEN CAST(1 AS bit) +END AS [IsNull], [l].[Id], [l].[CapitalName], [l].[Name], [l].[ServerAddress], [l].[CommanderName], [l].[Eradicated], CASE + WHEN [l].[Id] IS NULL THEN CAST(1 AS bit) ELSE CAST(0 AS bit) -END AS [IsNull], [l2].[Id], [l2].[IsOperational], [l2].[Name], CASE - WHEN [l2].[Id] IS NULL THEN CAST(1 AS bit) +END AS [IsNull], [l0].[Id], [l0].[IsOperational], [l0].[Name], CASE + WHEN [l0].[Id] IS NULL THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END AS [IsNull] FROM ( - SELECT [l].[Name], [l].[LocustHordeId], [l].[ThreatLevel], [l].[ThreatLevelByte], [l].[ThreatLevelNullableByte], NULL AS [DefeatedByNickname], NULL AS [DefeatedBySquadId], NULL AS [HighCommandId], N'LocustLeader' AS [Discriminator] - FROM [LocustLeaders] AS [l] + SELECT [l1].[Name], [l1].[LocustHordeId], [l1].[ThreatLevel], [l1].[ThreatLevelByte], [l1].[ThreatLevelNullableByte], NULL AS [DefeatedByNickname], NULL AS [DefeatedBySquadId], NULL AS [HighCommandId], N'LocustLeader' AS [Discriminator] + FROM [LocustLeaders] AS [l1] UNION ALL - SELECT [l0].[Name], [l0].[LocustHordeId], [l0].[ThreatLevel], [l0].[ThreatLevelByte], [l0].[ThreatLevelNullableByte], [l0].[DefeatedByNickname], [l0].[DefeatedBySquadId], [l0].[HighCommandId], N'LocustCommander' AS [Discriminator] - FROM [LocustCommanders] AS [l0] + SELECT [l2].[Name], [l2].[LocustHordeId], [l2].[ThreatLevel], [l2].[ThreatLevelByte], [l2].[ThreatLevelNullableByte], [l2].[DefeatedByNickname], [l2].[DefeatedBySquadId], [l2].[HighCommandId], N'LocustCommander' AS [Discriminator] + FROM [LocustCommanders] AS [l2] ) AS [t] LEFT JOIN ( SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], N'Gear' AS [Discriminator] @@ -10764,8 +10725,8 @@ UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] ) AS [t0] ON [t].[DefeatedByNickname] = [t0].[Nickname] AND [t].[DefeatedBySquadId] = [t0].[SquadId] -LEFT JOIN [LocustHordes] AS [l1] ON [t].[Name] = [l1].[CommanderName] -LEFT JOIN [LocustHighCommands] AS [l2] ON [t].[HighCommandId] = [l2].[Id]"); +LEFT JOIN [LocustHordes] AS [l] ON [t].[Name] = [l].[CommanderName] +LEFT JOIN [LocustHighCommands] AS [l0] ON [t].[HighCommandId] = [l0].[Id]"); } public override async Task Join_entity_with_itself_grouped_by_key_followed_by_include_skip_take(bool async) @@ -10934,7 +10895,7 @@ public override async Task Correlated_collection_via_SelectMany_with_Distinct_mi await base.Correlated_collection_via_SelectMany_with_Distinct_missing_indentifying_columns_in_projection(async); AssertSql( - @"SELECT [t].[Nickname], [t].[SquadId], [t3].[HasSoulPatch] + @"SELECT [t].[Nickname], [t].[SquadId], [t1].[HasSoulPatch] FROM ( SELECT [g].[Nickname], [g].[SquadId], [g].[FullName] FROM [Gears] AS [g] @@ -10943,7 +10904,7 @@ UNION ALL FROM [Officers] AS [o] ) AS [t] OUTER APPLY ( - SELECT DISTINCT [t1].[HasSoulPatch] + SELECT DISTINCT [t2].[HasSoulPatch] FROM [Weapons] AS [w] LEFT JOIN ( SELECT [g0].[AssignedCityName], [g0].[FullName] @@ -10959,9 +10920,9 @@ FROM [Gears] AS [g1] UNION ALL SELECT [o1].[CityOfBirthName], [o1].[HasSoulPatch] FROM [Officers] AS [o1] - ) AS [t1] ON [c].[Name] = [t1].[CityOfBirthName] + ) AS [t2] ON [c].[Name] = [t2].[CityOfBirthName] WHERE [t].[FullName] = [w].[OwnerFullName] -) AS [t3] +) AS [t1] ORDER BY [t].[Nickname], [t].[SquadId]"); } @@ -11240,7 +11201,7 @@ public override async Task Include_after_SelectMany_throws(bool async) await base.Include_after_SelectMany_throws(async); AssertSql( - @"SELECT [t0].[Nickname], [t0].[SquadId], [t0].[AssignedCityName], [t0].[CityOfBirthName], [t0].[FullName], [t0].[HasSoulPatch], [t0].[LeaderNickname], [t0].[LeaderSquadId], [t0].[Rank], [t0].[Discriminator], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] + @"SELECT [t].[Nickname], [t].[SquadId], [t].[AssignedCityName], [t].[CityOfBirthName], [t].[FullName], [t].[HasSoulPatch], [t].[LeaderNickname], [t].[LeaderSquadId], [t].[Rank], [t].[Discriminator], [s].[Id], [s].[Banner], [s].[Banner5], [s].[InternalNumber], [s].[Name] FROM [LocustHordes] AS [l] LEFT JOIN [Cities] AS [c] ON [l].[CapitalName] = [c].[Name] INNER JOIN ( @@ -11249,8 +11210,8 @@ FROM [Gears] AS [g] UNION ALL SELECT [o].[Nickname], [o].[SquadId], [o].[AssignedCityName], [o].[CityOfBirthName], [o].[FullName], [o].[HasSoulPatch], [o].[LeaderNickname], [o].[LeaderSquadId], [o].[Rank], N'Officer' AS [Discriminator] FROM [Officers] AS [o] -) AS [t0] ON [c].[Name] = [t0].[CityOfBirthName] -INNER JOIN [Squads] AS [s] ON [t0].[SquadId] = [s].[Id]"); +) AS [t] ON [c].[Name] = [t].[CityOfBirthName] +INNER JOIN [Squads] AS [s] ON [t].[SquadId] = [s].[Id]"); } public override async Task Correlated_collection_with_distinct_projecting_identifier_column_composite_key(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPCInheritanceQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPCInheritanceQuerySqlServerTest.cs index 9f3c6de706a..3ac85f46742 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPCInheritanceQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPCInheritanceQuerySqlServerTest.cs @@ -51,7 +51,7 @@ public override async Task Can_include_animals(bool async) await base.Can_include_animals(async); AssertSql( - @"SELECT [c].[Id], [c].[Name], [t0].[Species], [t0].[CountryId], [t0].[Name], [t0].[EagleId], [t0].[IsFlightless], [t0].[Group], [t0].[FoundOn], [t0].[Discriminator] + @"SELECT [c].[Id], [c].[Name], [t].[Species], [t].[CountryId], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[Group], [t].[FoundOn], [t].[Discriminator] FROM [Countries] AS [c] LEFT JOIN ( SELECT [e].[Species], [e].[CountryId], [e].[Name], [e].[EagleId], [e].[IsFlightless], [e].[Group], NULL AS [FoundOn], N'Eagle' AS [Discriminator] @@ -59,7 +59,7 @@ FROM [Eagle] AS [e] UNION ALL SELECT [k].[Species], [k].[CountryId], [k].[Name], [k].[EagleId], [k].[IsFlightless], NULL AS [Group], [k].[FoundOn], N'Kiwi' AS [Discriminator] FROM [Kiwi] AS [k] -) AS [t0] ON [c].[Id] = [t0].[CountryId] +) AS [t] ON [c].[Id] = [t].[CountryId] ORDER BY [c].[Name], [c].[Id]"); } @@ -341,7 +341,6 @@ UNION ALL SELECT [k].[Species], [k].[CountryId], [k].[Name], [k].[EagleId], [k].[IsFlightless], NULL AS [Group], [k].[FoundOn], N'Kiwi' AS [Discriminator] FROM [Kiwi] AS [k] ) AS [t] -WHERE [t].[Discriminator] IN (N'Eagle', N'Kiwi') ORDER BY [t].[Species]"); } @@ -358,7 +357,6 @@ UNION ALL SELECT [k].[Species], [k].[CountryId], [k].[Name], [k].[EagleId], [k].[IsFlightless], NULL AS [Group], [k].[FoundOn], N'Kiwi' AS [Discriminator] FROM [Kiwi] AS [k] ) AS [t] -WHERE [t].[Discriminator] IN (N'Eagle', N'Kiwi') ORDER BY [t].[Species]"); } @@ -375,7 +373,7 @@ UNION ALL SELECT [k].[Species], [k].[CountryId], [k].[Name], [k].[EagleId], [k].[IsFlightless], NULL AS [Group], [k].[FoundOn], N'Kiwi' AS [Discriminator] FROM [Kiwi] AS [k] ) AS [t] -WHERE [t].[CountryId] = 1 AND [t].[Discriminator] IN (N'Eagle', N'Kiwi') +WHERE [t].[CountryId] = 1 ORDER BY [t].[Species]"); } @@ -384,15 +382,11 @@ public override async Task Can_use_of_type_bird_with_projection(bool async) await base.Can_use_of_type_bird_with_projection(async); AssertSql( - @"SELECT [t].[EagleId] -FROM ( - SELECT [e].[EagleId], N'Eagle' AS [Discriminator] - FROM [Eagle] AS [e] - UNION ALL - SELECT [k].[EagleId], N'Kiwi' AS [Discriminator] - FROM [Kiwi] AS [k] -) AS [t] -WHERE [t].[Discriminator] IN (N'Eagle', N'Kiwi')"); + @"SELECT [e].[EagleId] +FROM [Eagle] AS [e] +UNION ALL +SELECT [k].[EagleId] +FROM [Kiwi] AS [k]"); } public override async Task Can_use_of_type_kiwi(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPCManyToManyNoTrackingQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPCManyToManyNoTrackingQuerySqlServerTest.cs index e1ee9b4e194..5d49430a139 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPCManyToManyNoTrackingQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPCManyToManyNoTrackingQuerySqlServerTest.cs @@ -105,8 +105,8 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [j].[EntityBranchId] = [t0].[Id] - WHERE [e].[Id] = [j].[EntityOneId] AND [t0].[Name] IS NOT NULL AND ([t0].[Name] LIKE N'L%')), [e].[Id]"); + ) AS [t] ON [j].[EntityBranchId] = [t].[Id] + WHERE [e].[Id] = [j].[EntityOneId] AND [t].[Name] IS NOT NULL AND ([t].[Name] LIKE N'L%')), [e].[Id]"); } public override async Task Skip_navigation_long_count_without_predicate(bool async) @@ -170,10 +170,10 @@ public override async Task Skip_navigation_select_many_min(bool async) await base.Skip_navigation_select_many_min(async); AssertSql( - @"SELECT MIN([t1].[Id]) + @"SELECT MIN([t0].[Id]) FROM [EntityThrees] AS [e] INNER JOIN ( - SELECT [t0].[Id], [e0].[ThreeSkipSharedId] + SELECT [t].[Id], [e0].[ThreeSkipSharedId] FROM [EntityRootEntityThree] AS [e0] INNER JOIN ( SELECT [r].[Id] @@ -184,8 +184,8 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] -) AS [t1] ON [e].[Id] = [t1].[ThreeSkipSharedId]"); + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] +) AS [t0] ON [e].[Id] = [t0].[ThreeSkipSharedId]"); } public override async Task Skip_navigation_select_many_sum(bool async) @@ -363,10 +363,10 @@ public override async Task Skip_navigation_of_type(bool async) await base.Skip_navigation_of_type(async); AssertSql( - @"SELECT [e].[Key1], [e].[Key2], [e].[Key3], [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator], [t1].[RootSkipSharedId], [t1].[CompositeKeySkipSharedKey1], [t1].[CompositeKeySkipSharedKey2], [t1].[CompositeKeySkipSharedKey3] + @"SELECT [e].[Key1], [e].[Key2], [e].[Key3], [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [t0].[RootSkipSharedId], [t0].[CompositeKeySkipSharedKey1], [t0].[CompositeKeySkipSharedKey2], [t0].[CompositeKeySkipSharedKey3] FROM [EntityCompositeKeys] AS [e] LEFT JOIN ( - SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3] + SELECT [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator], [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3] FROM [EntityCompositeKeyEntityRoot] AS [e0] INNER JOIN ( SELECT [r].[Id], [r].[Name], NULL AS [Number], NULL AS [IsGreen], N'EntityRoot' AS [Discriminator] @@ -377,10 +377,10 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] - WHERE [t0].[Discriminator] = N'EntityLeaf' -) AS [t1] ON [e].[Key1] = [t1].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t1].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t1].[CompositeKeySkipSharedKey3] -ORDER BY [e].[Key1], [e].[Key2], [e].[Key3], [t1].[RootSkipSharedId], [t1].[CompositeKeySkipSharedKey1], [t1].[CompositeKeySkipSharedKey2], [t1].[CompositeKeySkipSharedKey3]"); + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] + WHERE [t].[Discriminator] = N'EntityLeaf' +) AS [t0] ON [e].[Key1] = [t0].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t0].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t0].[CompositeKeySkipSharedKey3] +ORDER BY [e].[Key1], [e].[Key2], [e].[Key3], [t0].[RootSkipSharedId], [t0].[CompositeKeySkipSharedKey1], [t0].[CompositeKeySkipSharedKey2], [t0].[CompositeKeySkipSharedKey3]"); } public override async Task Join_with_skip_navigation(bool async) @@ -515,10 +515,10 @@ public override async Task Select_many_over_skip_navigation_of_type(bool async) await base.Select_many_over_skip_navigation_of_type(async); AssertSql( - @"SELECT [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator] + @"SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator] FROM [EntityThrees] AS [e] INNER JOIN ( - SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e0].[ThreeSkipSharedId] + SELECT [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator], [e0].[ThreeSkipSharedId] FROM [EntityRootEntityThree] AS [e0] INNER JOIN ( SELECT [r].[Id], [r].[Name], NULL AS [Number], NULL AS [IsGreen], N'EntityRoot' AS [Discriminator] @@ -529,9 +529,9 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] - WHERE [t0].[Discriminator] IN (N'EntityBranch', N'EntityLeaf') -) AS [t1] ON [e].[Id] = [t1].[ThreeSkipSharedId]"); + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] + WHERE [t].[Discriminator] IN (N'EntityBranch', N'EntityLeaf') +) AS [t0] ON [e].[Id] = [t0].[ThreeSkipSharedId]"); } public override async Task Select_many_over_skip_navigation_cast(bool async) @@ -539,10 +539,10 @@ public override async Task Select_many_over_skip_navigation_cast(bool async) await base.Select_many_over_skip_navigation_cast(async); AssertSql( - @"SELECT [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator] + @"SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator] FROM [EntityOnes] AS [e] INNER JOIN ( - SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [j].[EntityOneId] + SELECT [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator], [j].[EntityOneId] FROM [JoinOneToBranch] AS [j] INNER JOIN ( SELECT [b].[Id], [b].[Name], [b].[Number], NULL AS [IsGreen], N'EntityBranch' AS [Discriminator] @@ -550,8 +550,8 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [j].[EntityBranchId] = [t0].[Id] -) AS [t1] ON [e].[Id] = [t1].[EntityOneId]"); + ) AS [t] ON [j].[EntityBranchId] = [t].[Id] +) AS [t0] ON [e].[Id] = [t0].[EntityOneId]"); } public override async Task Select_skip_navigation(bool async) @@ -618,10 +618,10 @@ public override async Task Include_skip_navigation(bool async) await base.Include_skip_navigation(async); AssertSql( - @"SELECT [e].[Key1], [e].[Key2], [e].[Key3], [e].[Name], [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator], [t1].[RootSkipSharedId], [t1].[CompositeKeySkipSharedKey1], [t1].[CompositeKeySkipSharedKey2], [t1].[CompositeKeySkipSharedKey3] + @"SELECT [e].[Key1], [e].[Key2], [e].[Key3], [e].[Name], [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [t0].[RootSkipSharedId], [t0].[CompositeKeySkipSharedKey1], [t0].[CompositeKeySkipSharedKey2], [t0].[CompositeKeySkipSharedKey3] FROM [EntityCompositeKeys] AS [e] LEFT JOIN ( - SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3] + SELECT [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator], [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3] FROM [EntityCompositeKeyEntityRoot] AS [e0] INNER JOIN ( SELECT [r].[Id], [r].[Name], NULL AS [Number], NULL AS [IsGreen], N'EntityRoot' AS [Discriminator] @@ -632,9 +632,9 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] -) AS [t1] ON [e].[Key1] = [t1].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t1].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t1].[CompositeKeySkipSharedKey3] -ORDER BY [e].[Key1], [e].[Key2], [e].[Key3], [t1].[RootSkipSharedId], [t1].[CompositeKeySkipSharedKey1], [t1].[CompositeKeySkipSharedKey2], [t1].[CompositeKeySkipSharedKey3]"); + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] +) AS [t0] ON [e].[Key1] = [t0].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t0].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t0].[CompositeKeySkipSharedKey3] +ORDER BY [e].[Key1], [e].[Key2], [e].[Key3], [t0].[RootSkipSharedId], [t0].[CompositeKeySkipSharedKey1], [t0].[CompositeKeySkipSharedKey2], [t0].[CompositeKeySkipSharedKey3]"); } public override async Task Include_skip_navigation_then_reference(bool async) @@ -957,7 +957,7 @@ public override async Task Filter_include_on_skip_navigation_combined_with_filte await base.Filter_include_on_skip_navigation_combined_with_filtered_then_includes(async); AssertSql( - @"SELECT [e].[Id], [e].[CollectionInverseId], [e].[Name], [e].[ReferenceInverseId], [t4].[Id], [t4].[Name], [t4].[OneId], [t4].[ThreeId], [t4].[Id0], [t4].[CollectionInverseId], [t4].[ExtraId], [t4].[Name0], [t4].[ReferenceInverseId], [t4].[OneId0], [t4].[TwoId], [t4].[Id1], [t4].[Name1], [t4].[Number], [t4].[IsGreen], [t4].[Discriminator], [t4].[EntityBranchId], [t4].[EntityOneId] + @"SELECT [e].[Id], [e].[CollectionInverseId], [e].[Name], [e].[ReferenceInverseId], [t3].[Id], [t3].[Name], [t3].[OneId], [t3].[ThreeId], [t3].[Id0], [t3].[CollectionInverseId], [t3].[ExtraId], [t3].[Name0], [t3].[ReferenceInverseId], [t3].[OneId0], [t3].[TwoId], [t3].[Id1], [t3].[Name1], [t3].[Number], [t3].[IsGreen], [t3].[Discriminator], [t3].[EntityBranchId], [t3].[EntityOneId] FROM [EntityThrees] AS [e] LEFT JOIN ( SELECT [e0].[Id], [e0].[Name], [j].[OneId], [j].[ThreeId], [t0].[Id] AS [Id0], [t0].[CollectionInverseId], [t0].[ExtraId], [t0].[Name] AS [Name0], [t0].[ReferenceInverseId], [t0].[OneId] AS [OneId0], [t0].[TwoId], [t1].[Id] AS [Id1], [t1].[Name] AS [Name1], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator], [t1].[EntityBranchId], [t1].[EntityOneId] @@ -985,8 +985,8 @@ FROM [Leaves] AS [l] WHERE [t2].[Id] < 20 ) AS [t1] ON [e0].[Id] = [t1].[EntityOneId] WHERE [e0].[Id] < 10 -) AS [t4] ON [e].[Id] = [t4].[ThreeId] -ORDER BY [e].[Id], [t4].[OneId], [t4].[ThreeId], [t4].[Id], [t4].[OneId0], [t4].[Id0], [t4].[TwoId], [t4].[EntityBranchId], [t4].[EntityOneId]"); +) AS [t3] ON [e].[Id] = [t3].[ThreeId] +ORDER BY [e].[Id], [t3].[OneId], [t3].[ThreeId], [t3].[Id], [t3].[OneId0], [t3].[Id0], [t3].[TwoId], [t3].[EntityBranchId], [t3].[EntityOneId]"); } public override async Task Filtered_include_on_skip_navigation_then_filtered_include_on_navigation(bool async) @@ -1054,10 +1054,10 @@ public override async Task Include_skip_navigation_split(bool async) FROM [EntityCompositeKeys] AS [e] ORDER BY [e].[Key1], [e].[Key2], [e].[Key3]", // - @"SELECT [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator], [e].[Key1], [e].[Key2], [e].[Key3] + @"SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e].[Key1], [e].[Key2], [e].[Key3] FROM [EntityCompositeKeys] AS [e] INNER JOIN ( - SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3] + SELECT [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3] FROM [EntityCompositeKeyEntityRoot] AS [e0] INNER JOIN ( SELECT [r].[Id], [r].[Name], NULL AS [Number], NULL AS [IsGreen], N'EntityRoot' AS [Discriminator] @@ -1068,8 +1068,8 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] -) AS [t1] ON [e].[Key1] = [t1].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t1].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t1].[CompositeKeySkipSharedKey3] + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] +) AS [t0] ON [e].[Key1] = [t0].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t0].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t0].[CompositeKeySkipSharedKey3] ORDER BY [e].[Key1], [e].[Key2], [e].[Key3]"); } @@ -1602,7 +1602,7 @@ FROM [JoinOneToTwo] AS [j0] ) AS [t0] ON [t].[Id] = [t0].[OneId] ORDER BY [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id], [t0].[OneId], [t0].[Id]", // - @"SELECT [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator], [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id] + @"SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id] FROM [EntityThrees] AS [e] INNER JOIN ( SELECT [e0].[Id], [j].[OneId], [j].[ThreeId] @@ -1611,7 +1611,7 @@ FROM [JoinOneToThreePayloadFull] AS [j] WHERE [e0].[Id] < 10 ) AS [t] ON [e].[Id] = [t].[ThreeId] INNER JOIN ( - SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [j0].[EntityOneId] + SELECT [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator], [j0].[EntityOneId] FROM [JoinOneToBranch] AS [j0] INNER JOIN ( SELECT [b].[Id], [b].[Name], [b].[Number], NULL AS [IsGreen], N'EntityBranch' AS [Discriminator] @@ -1619,9 +1619,9 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [j0].[EntityBranchId] = [t0].[Id] - WHERE [t0].[Id] < 20 -) AS [t1] ON [t].[Id] = [t1].[EntityOneId] + ) AS [t1] ON [j0].[EntityBranchId] = [t1].[Id] + WHERE [t1].[Id] < 20 +) AS [t0] ON [t].[Id] = [t0].[EntityOneId] ORDER BY [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id]"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPCManyToManyQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPCManyToManyQuerySqlServerTest.cs index 20993104767..a30acbabfb4 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPCManyToManyQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPCManyToManyQuerySqlServerTest.cs @@ -105,8 +105,8 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [j].[EntityBranchId] = [t0].[Id] - WHERE [e].[Id] = [j].[EntityOneId] AND [t0].[Name] IS NOT NULL AND ([t0].[Name] LIKE N'L%')), [e].[Id]"); + ) AS [t] ON [j].[EntityBranchId] = [t].[Id] + WHERE [e].[Id] = [j].[EntityOneId] AND [t].[Name] IS NOT NULL AND ([t].[Name] LIKE N'L%')), [e].[Id]"); } public override async Task Skip_navigation_long_count_without_predicate(bool async) @@ -170,10 +170,10 @@ public override async Task Skip_navigation_select_many_min(bool async) await base.Skip_navigation_select_many_min(async); AssertSql( - @"SELECT MIN([t1].[Id]) + @"SELECT MIN([t0].[Id]) FROM [EntityThrees] AS [e] INNER JOIN ( - SELECT [t0].[Id], [e0].[ThreeSkipSharedId] + SELECT [t].[Id], [e0].[ThreeSkipSharedId] FROM [EntityRootEntityThree] AS [e0] INNER JOIN ( SELECT [r].[Id] @@ -184,8 +184,8 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] -) AS [t1] ON [e].[Id] = [t1].[ThreeSkipSharedId]"); + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] +) AS [t0] ON [e].[Id] = [t0].[ThreeSkipSharedId]"); } public override async Task Skip_navigation_select_many_sum(bool async) @@ -363,10 +363,10 @@ public override async Task Skip_navigation_of_type(bool async) await base.Skip_navigation_of_type(async); AssertSql( - @"SELECT [e].[Key1], [e].[Key2], [e].[Key3], [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator], [t1].[RootSkipSharedId], [t1].[CompositeKeySkipSharedKey1], [t1].[CompositeKeySkipSharedKey2], [t1].[CompositeKeySkipSharedKey3] + @"SELECT [e].[Key1], [e].[Key2], [e].[Key3], [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [t0].[RootSkipSharedId], [t0].[CompositeKeySkipSharedKey1], [t0].[CompositeKeySkipSharedKey2], [t0].[CompositeKeySkipSharedKey3] FROM [EntityCompositeKeys] AS [e] LEFT JOIN ( - SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3] + SELECT [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator], [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3] FROM [EntityCompositeKeyEntityRoot] AS [e0] INNER JOIN ( SELECT [r].[Id], [r].[Name], NULL AS [Number], NULL AS [IsGreen], N'EntityRoot' AS [Discriminator] @@ -377,10 +377,10 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] - WHERE [t0].[Discriminator] = N'EntityLeaf' -) AS [t1] ON [e].[Key1] = [t1].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t1].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t1].[CompositeKeySkipSharedKey3] -ORDER BY [e].[Key1], [e].[Key2], [e].[Key3], [t1].[RootSkipSharedId], [t1].[CompositeKeySkipSharedKey1], [t1].[CompositeKeySkipSharedKey2], [t1].[CompositeKeySkipSharedKey3]"); + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] + WHERE [t].[Discriminator] = N'EntityLeaf' +) AS [t0] ON [e].[Key1] = [t0].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t0].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t0].[CompositeKeySkipSharedKey3] +ORDER BY [e].[Key1], [e].[Key2], [e].[Key3], [t0].[RootSkipSharedId], [t0].[CompositeKeySkipSharedKey1], [t0].[CompositeKeySkipSharedKey2], [t0].[CompositeKeySkipSharedKey3]"); } public override async Task Join_with_skip_navigation(bool async) @@ -515,10 +515,10 @@ public override async Task Select_many_over_skip_navigation_of_type(bool async) await base.Select_many_over_skip_navigation_of_type(async); AssertSql( - @"SELECT [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator] + @"SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator] FROM [EntityThrees] AS [e] INNER JOIN ( - SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e0].[ThreeSkipSharedId] + SELECT [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator], [e0].[ThreeSkipSharedId] FROM [EntityRootEntityThree] AS [e0] INNER JOIN ( SELECT [r].[Id], [r].[Name], NULL AS [Number], NULL AS [IsGreen], N'EntityRoot' AS [Discriminator] @@ -529,9 +529,9 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] - WHERE [t0].[Discriminator] IN (N'EntityBranch', N'EntityLeaf') -) AS [t1] ON [e].[Id] = [t1].[ThreeSkipSharedId]"); + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] + WHERE [t].[Discriminator] IN (N'EntityBranch', N'EntityLeaf') +) AS [t0] ON [e].[Id] = [t0].[ThreeSkipSharedId]"); } public override async Task Select_many_over_skip_navigation_cast(bool async) @@ -539,10 +539,10 @@ public override async Task Select_many_over_skip_navigation_cast(bool async) await base.Select_many_over_skip_navigation_cast(async); AssertSql( - @"SELECT [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator] + @"SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator] FROM [EntityOnes] AS [e] INNER JOIN ( - SELECT [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [j].[EntityOneId] + SELECT [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator], [j].[EntityOneId] FROM [JoinOneToBranch] AS [j] INNER JOIN ( SELECT [b].[Id], [b].[Name], [b].[Number], NULL AS [IsGreen], N'EntityBranch' AS [Discriminator] @@ -550,8 +550,8 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [j].[EntityBranchId] = [t0].[Id] -) AS [t1] ON [e].[Id] = [t1].[EntityOneId]"); + ) AS [t] ON [j].[EntityBranchId] = [t].[Id] +) AS [t0] ON [e].[Id] = [t0].[EntityOneId]"); } public override async Task Select_skip_navigation(bool async) @@ -618,10 +618,10 @@ public override async Task Include_skip_navigation(bool async) await base.Include_skip_navigation(async); AssertSql( - @"SELECT [e].[Key1], [e].[Key2], [e].[Key3], [e].[Name], [t1].[RootSkipSharedId], [t1].[CompositeKeySkipSharedKey1], [t1].[CompositeKeySkipSharedKey2], [t1].[CompositeKeySkipSharedKey3], [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator] + @"SELECT [e].[Key1], [e].[Key2], [e].[Key3], [e].[Name], [t0].[RootSkipSharedId], [t0].[CompositeKeySkipSharedKey1], [t0].[CompositeKeySkipSharedKey2], [t0].[CompositeKeySkipSharedKey3], [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator] FROM [EntityCompositeKeys] AS [e] LEFT JOIN ( - SELECT [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3], [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator] + SELECT [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3], [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator] FROM [EntityCompositeKeyEntityRoot] AS [e0] INNER JOIN ( SELECT [r].[Id], [r].[Name], NULL AS [Number], NULL AS [IsGreen], N'EntityRoot' AS [Discriminator] @@ -632,9 +632,9 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] -) AS [t1] ON [e].[Key1] = [t1].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t1].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t1].[CompositeKeySkipSharedKey3] -ORDER BY [e].[Key1], [e].[Key2], [e].[Key3], [t1].[RootSkipSharedId], [t1].[CompositeKeySkipSharedKey1], [t1].[CompositeKeySkipSharedKey2], [t1].[CompositeKeySkipSharedKey3]"); + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] +) AS [t0] ON [e].[Key1] = [t0].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t0].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t0].[CompositeKeySkipSharedKey3] +ORDER BY [e].[Key1], [e].[Key2], [e].[Key3], [t0].[RootSkipSharedId], [t0].[CompositeKeySkipSharedKey1], [t0].[CompositeKeySkipSharedKey2], [t0].[CompositeKeySkipSharedKey3]"); } public override async Task Include_skip_navigation_then_reference(bool async) @@ -957,7 +957,7 @@ public override async Task Filter_include_on_skip_navigation_combined_with_filte await base.Filter_include_on_skip_navigation_combined_with_filtered_then_includes(async); AssertSql( - @"SELECT [e].[Id], [e].[CollectionInverseId], [e].[Name], [e].[ReferenceInverseId], [t4].[OneId], [t4].[ThreeId], [t4].[Payload], [t4].[Id], [t4].[Name], [t4].[OneId0], [t4].[TwoId], [t4].[JoinOneToTwoExtraId], [t4].[Id0], [t4].[CollectionInverseId], [t4].[ExtraId], [t4].[Name0], [t4].[ReferenceInverseId], [t4].[EntityBranchId], [t4].[EntityOneId], [t4].[Id1], [t4].[Name1], [t4].[Number], [t4].[IsGreen], [t4].[Discriminator] + @"SELECT [e].[Id], [e].[CollectionInverseId], [e].[Name], [e].[ReferenceInverseId], [t3].[OneId], [t3].[ThreeId], [t3].[Payload], [t3].[Id], [t3].[Name], [t3].[OneId0], [t3].[TwoId], [t3].[JoinOneToTwoExtraId], [t3].[Id0], [t3].[CollectionInverseId], [t3].[ExtraId], [t3].[Name0], [t3].[ReferenceInverseId], [t3].[EntityBranchId], [t3].[EntityOneId], [t3].[Id1], [t3].[Name1], [t3].[Number], [t3].[IsGreen], [t3].[Discriminator] FROM [EntityThrees] AS [e] LEFT JOIN ( SELECT [j].[OneId], [j].[ThreeId], [j].[Payload], [e0].[Id], [e0].[Name], [t0].[OneId] AS [OneId0], [t0].[TwoId], [t0].[JoinOneToTwoExtraId], [t0].[Id] AS [Id0], [t0].[CollectionInverseId], [t0].[ExtraId], [t0].[Name] AS [Name0], [t0].[ReferenceInverseId], [t1].[EntityBranchId], [t1].[EntityOneId], [t1].[Id] AS [Id1], [t1].[Name] AS [Name1], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator] @@ -985,8 +985,8 @@ FROM [Leaves] AS [l] WHERE [t2].[Id] < 20 ) AS [t1] ON [e0].[Id] = [t1].[EntityOneId] WHERE [e0].[Id] < 10 -) AS [t4] ON [e].[Id] = [t4].[ThreeId] -ORDER BY [e].[Id], [t4].[OneId], [t4].[ThreeId], [t4].[Id], [t4].[OneId0], [t4].[Id0], [t4].[TwoId], [t4].[EntityBranchId], [t4].[EntityOneId]"); +) AS [t3] ON [e].[Id] = [t3].[ThreeId] +ORDER BY [e].[Id], [t3].[OneId], [t3].[ThreeId], [t3].[Id], [t3].[OneId0], [t3].[Id0], [t3].[TwoId], [t3].[EntityBranchId], [t3].[EntityOneId]"); } public override async Task Filtered_include_on_skip_navigation_then_filtered_include_on_navigation(bool async) @@ -1054,10 +1054,10 @@ public override async Task Include_skip_navigation_split(bool async) FROM [EntityCompositeKeys] AS [e] ORDER BY [e].[Key1], [e].[Key2], [e].[Key3]", // - @"SELECT [t1].[RootSkipSharedId], [t1].[CompositeKeySkipSharedKey1], [t1].[CompositeKeySkipSharedKey2], [t1].[CompositeKeySkipSharedKey3], [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator], [e].[Key1], [e].[Key2], [e].[Key3] + @"SELECT [t0].[RootSkipSharedId], [t0].[CompositeKeySkipSharedKey1], [t0].[CompositeKeySkipSharedKey2], [t0].[CompositeKeySkipSharedKey3], [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e].[Key1], [e].[Key2], [e].[Key3] FROM [EntityCompositeKeys] AS [e] INNER JOIN ( - SELECT [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3], [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator] + SELECT [e0].[RootSkipSharedId], [e0].[CompositeKeySkipSharedKey1], [e0].[CompositeKeySkipSharedKey2], [e0].[CompositeKeySkipSharedKey3], [t].[Id], [t].[Name], [t].[Number], [t].[IsGreen], [t].[Discriminator] FROM [EntityCompositeKeyEntityRoot] AS [e0] INNER JOIN ( SELECT [r].[Id], [r].[Name], NULL AS [Number], NULL AS [IsGreen], N'EntityRoot' AS [Discriminator] @@ -1068,8 +1068,8 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [e0].[RootSkipSharedId] = [t0].[Id] -) AS [t1] ON [e].[Key1] = [t1].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t1].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t1].[CompositeKeySkipSharedKey3] + ) AS [t] ON [e0].[RootSkipSharedId] = [t].[Id] +) AS [t0] ON [e].[Key1] = [t0].[CompositeKeySkipSharedKey1] AND [e].[Key2] = [t0].[CompositeKeySkipSharedKey2] AND [e].[Key3] = [t0].[CompositeKeySkipSharedKey3] ORDER BY [e].[Key1], [e].[Key2], [e].[Key3]"); } @@ -1602,7 +1602,7 @@ FROM [JoinOneToTwo] AS [j0] ) AS [t0] ON [t].[Id] = [t0].[OneId] ORDER BY [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id], [t0].[OneId], [t0].[Id]", // - @"SELECT [t1].[EntityBranchId], [t1].[EntityOneId], [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator], [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id] + @"SELECT [t0].[EntityBranchId], [t0].[EntityOneId], [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator], [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id] FROM [EntityThrees] AS [e] INNER JOIN ( SELECT [j].[OneId], [j].[ThreeId], [e0].[Id] @@ -1611,7 +1611,7 @@ FROM [JoinOneToThreePayloadFull] AS [j] WHERE [e0].[Id] < 10 ) AS [t] ON [e].[Id] = [t].[ThreeId] INNER JOIN ( - SELECT [j0].[EntityBranchId], [j0].[EntityOneId], [t0].[Id], [t0].[Name], [t0].[Number], [t0].[IsGreen], [t0].[Discriminator] + SELECT [j0].[EntityBranchId], [j0].[EntityOneId], [t1].[Id], [t1].[Name], [t1].[Number], [t1].[IsGreen], [t1].[Discriminator] FROM [JoinOneToBranch] AS [j0] INNER JOIN ( SELECT [b].[Id], [b].[Name], [b].[Number], NULL AS [IsGreen], N'EntityBranch' AS [Discriminator] @@ -1619,9 +1619,9 @@ FROM [Branches] AS [b] UNION ALL SELECT [l].[Id], [l].[Name], [l].[Number], [l].[IsGreen], N'EntityLeaf' AS [Discriminator] FROM [Leaves] AS [l] - ) AS [t0] ON [j0].[EntityBranchId] = [t0].[Id] - WHERE [t0].[Id] < 20 -) AS [t1] ON [t].[Id] = [t1].[EntityOneId] + ) AS [t1] ON [j0].[EntityBranchId] = [t1].[Id] + WHERE [t1].[Id] < 20 +) AS [t0] ON [t].[Id] = [t0].[EntityOneId] ORDER BY [e].[Id], [t].[OneId], [t].[ThreeId], [t].[Id]"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPCRelationshipsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPCRelationshipsQuerySqlServerTest.cs index 38581000161..c7507321367 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPCRelationshipsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPCRelationshipsQuerySqlServerTest.cs @@ -24,36 +24,36 @@ public override void Changes_in_derived_related_entities_are_detected() base.Changes_in_derived_related_entities_are_detected(); AssertSql( - @"SELECT [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [t1].[BaseInheritanceRelationshipEntityId], [t1].[Id1], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t1].[Id0], [t1].[Name0], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name], [t2].[Id], [t2].[BaseParentId], [t2].[Name], [t2].[DerivedProperty], [t2].[Discriminator] + @"SELECT [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [t1].[BaseInheritanceRelationshipEntityId], [t1].[Id1], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t1].[Id0], [t1].[Name0], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name], [t2].[Id], [t2].[BaseParentId], [t2].[Name], [t2].[DerivedProperty], [t2].[Discriminator] FROM ( SELECT TOP(2) [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [o].[Id] AS [Id0], [o].[Name] AS [Name0], [t0].[Id] AS [Id1], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM ( - SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] - FROM [BaseEntities] AS [b] + SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] + FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END WHERE [t].[Name] = N'Derived1(4)' ) AS [t1] LEFT JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t1].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] - FROM [BaseCollectionsOnBase] AS [b0] + SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] + FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d2].[Id], [d2].[BaseParentId], [d2].[Name], [d2].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] - FROM [DerivedCollectionsOnBase] AS [d2] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] + FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t2] ON [t1].[Id] = [t2].[BaseParentId] -ORDER BY [t1].[Id], [t1].[BaseInheritanceRelationshipEntityId], [t1].[Id1], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id]"); +ORDER BY [t1].[Id], [t1].[BaseInheritanceRelationshipEntityId], [t1].[Id1], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_without_inheritance(bool async) @@ -61,26 +61,26 @@ public override async Task Include_collection_without_inheritance(bool async) await base.Include_collection_without_inheritance(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [c].[Id], [c].[Name], [c].[ParentId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [c].[Id], [c].[Name], [c].[ParentId] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN [CollectionsOnBase] AS [c] ON [t].[Id] = [c].[ParentId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_without_inheritance_reverse(bool async) @@ -88,26 +88,26 @@ public override async Task Include_collection_without_inheritance_reverse(bool a await base.Include_collection_without_inheritance_reverse(async); AssertSql( - @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [c].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] +) AS [t] ON [c].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_collection_without_inheritance_with_filter(bool async) @@ -115,27 +115,27 @@ public override async Task Include_collection_without_inheritance_with_filter(bo await base.Include_collection_without_inheritance_with_filter(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [c].[Id], [c].[Name], [c].[ParentId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [c].[Id], [c].[Name], [c].[ParentId] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN [CollectionsOnBase] AS [c] ON [t].[Id] = [c].[ParentId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_without_inheritance_with_filter_reverse(bool async) @@ -143,27 +143,27 @@ public override async Task Include_collection_without_inheritance_with_filter_re await base.Include_collection_without_inheritance_with_filter_reverse(async); AssertSql( - @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [c].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] +) AS [t] ON [c].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [c].[Name] <> N'Bar' OR [c].[Name] IS NULL -ORDER BY [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_collection_with_inheritance(bool async) @@ -171,24 +171,24 @@ public override async Task Include_collection_with_inheritance(bool async) await base.Include_collection_with_inheritance(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b0] @@ -196,7 +196,7 @@ UNION ALL SELECT [d2].[Id], [d2].[BaseParentId], [d2].[Name], [d2].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] FROM [DerivedCollectionsOnBase] AS [d2] ) AS [t1] ON [t].[Id] = [t1].[BaseParentId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_with_inheritance_on_derived1(bool async) @@ -204,7 +204,7 @@ public override async Task Include_collection_with_inheritance_on_derived1(bool await base.Include_collection_with_inheritance_on_derived1(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] @@ -215,7 +215,7 @@ FROM [BaseCollectionsOnBase] AS [b] UNION ALL SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] FROM [DerivedCollectionsOnBase] AS [d1] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] +) AS [t] ON [d].[Id] = [t].[BaseParentId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } @@ -224,7 +224,7 @@ public override async Task Include_collection_with_inheritance_on_derived2(bool await base.Include_collection_with_inheritance_on_derived2(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[Id], [t0].[Name], [t0].[ParentId], [t0].[DerivedInheritanceRelationshipEntityId], [t0].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[Id], [t].[Name], [t].[ParentId], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] @@ -235,7 +235,7 @@ FROM [BaseCollectionsOnDerived] AS [b] UNION ALL SELECT [d1].[Id], [d1].[Name], [d1].[ParentId], [d1].[DerivedInheritanceRelationshipEntityId], N'DerivedCollectionOnDerived' AS [Discriminator] FROM [DerivedCollectionsOnDerived] AS [d1] -) AS [t0] ON [d].[Id] = [t0].[ParentId] +) AS [t] ON [d].[Id] = [t].[ParentId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } @@ -258,19 +258,19 @@ public override async Task Include_collection_with_inheritance_on_derived_revers await base.Include_collection_with_inheritance_on_derived_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[ParentId], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator], [d0].[Id], [d0].[Name], [d0].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[ParentId], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator], [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], [b].[ParentId], NULL AS [DerivedInheritanceRelationshipEntityId], N'BaseCollectionOnDerived' AS [Discriminator] FROM [BaseCollectionsOnDerived] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[ParentId], [d].[DerivedInheritanceRelationshipEntityId], N'DerivedCollectionOnDerived' AS [Discriminator] - FROM [DerivedCollectionsOnDerived] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[ParentId], [d1].[DerivedInheritanceRelationshipEntityId], N'DerivedCollectionOnDerived' AS [Discriminator] + FROM [DerivedCollectionsOnDerived] AS [d1] ) AS [t] -LEFT JOIN [DerivedEntities] AS [d0] ON [t].[ParentId] = [d0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [d0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [OwnedCollections] AS [o0] ON [d0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities] AS [d] ON [t].[ParentId] = [d].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_collection_with_inheritance_reverse(bool async) @@ -278,32 +278,32 @@ public override async Task Include_collection_with_inheritance_reverse(bool asyn await base.Include_collection_with_inheritance_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] + FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t0].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t0].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_collection_with_inheritance_with_filter(bool async) @@ -311,24 +311,24 @@ public override async Task Include_collection_with_inheritance_with_filter(bool await base.Include_collection_with_inheritance_with_filter(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b0] @@ -337,7 +337,7 @@ UNION ALL FROM [DerivedCollectionsOnBase] AS [d2] ) AS [t1] ON [t].[Id] = [t1].[BaseParentId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_with_inheritance_with_filter_reverse(bool async) @@ -345,33 +345,33 @@ public override async Task Include_collection_with_inheritance_with_filter_rever await base.Include_collection_with_inheritance_with_filter_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] + FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t0].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t0].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_without_inheritance(bool async) @@ -379,26 +379,26 @@ public override async Task Include_reference_without_inheritance(bool async) await base.Include_reference_without_inheritance(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [ReferencesOnBase] AS [r] ON [t].[Id] = [r].[ParentId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_without_inheritance_on_derived1(bool async) @@ -448,26 +448,26 @@ public override async Task Include_reference_without_inheritance_reverse(bool as await base.Include_reference_without_inheritance_reverse(async); AssertSql( - @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [ReferencesOnBase] AS [r] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [r].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] +) AS [t] ON [r].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [r].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [r].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_without_inheritance_with_filter(bool async) @@ -475,27 +475,27 @@ public override async Task Include_reference_without_inheritance_with_filter(boo await base.Include_reference_without_inheritance_with_filter(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [ReferencesOnBase] AS [r] ON [t].[Id] = [r].[ParentId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [t].[Id], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_without_inheritance_with_filter_reverse(bool async) @@ -503,27 +503,27 @@ public override async Task Include_reference_without_inheritance_with_filter_rev await base.Include_reference_without_inheritance_with_filter_reverse(async); AssertSql( - @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [ReferencesOnBase] AS [r] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [r].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] +) AS [t] ON [r].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [r].[Name] <> N'Bar' OR [r].[Name] IS NULL -ORDER BY [r].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [r].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance(bool async) @@ -531,32 +531,32 @@ public override async Task Include_reference_with_inheritance(bool async) await base.Include_reference_with_inheritance(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d0] + SELECT [d2].[Id], [d2].[BaseParentId], [d2].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d2] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_on_derived1(bool async) @@ -564,19 +564,19 @@ public override async Task Include_reference_with_inheritance_on_derived1(bool a await base.Include_reference_with_inheritance_on_derived1(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[BaseParentId], [t].[Name], [t].[Discriminator] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d1] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_on_derived2(bool async) @@ -584,19 +584,19 @@ public override async Task Include_reference_with_inheritance_on_derived2(bool a await base.Include_reference_with_inheritance_on_derived2(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedInheritanceRelationshipEntityId], [t0].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[BaseParentId], [t].[Name], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedInheritanceRelationshipEntityId], N'BaseReferenceOnDerived' AS [Discriminator] FROM [BaseReferencesOnDerived] AS [b] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedInheritanceRelationshipEntityId], N'DerivedReferenceOnDerived' AS [Discriminator] - FROM [DerivedReferencesOnDerived] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedInheritanceRelationshipEntityId], N'DerivedReferenceOnDerived' AS [Discriminator] + FROM [DerivedReferencesOnDerived] AS [d1] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_on_derived4(bool async) @@ -618,19 +618,19 @@ public override async Task Include_reference_with_inheritance_on_derived_reverse await base.Include_reference_with_inheritance_on_derived_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator], [d0].[Id], [d0].[Name], [d0].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator], [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedInheritanceRelationshipEntityId], N'BaseReferenceOnDerived' AS [Discriminator] FROM [BaseReferencesOnDerived] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedInheritanceRelationshipEntityId], N'DerivedReferenceOnDerived' AS [Discriminator] - FROM [DerivedReferencesOnDerived] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedInheritanceRelationshipEntityId], N'DerivedReferenceOnDerived' AS [Discriminator] + FROM [DerivedReferencesOnDerived] AS [d1] ) AS [t] -LEFT JOIN [DerivedEntities] AS [d0] ON [t].[BaseParentId] = [d0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [d0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [OwnedCollections] AS [o0] ON [d0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities] AS [d] ON [t].[BaseParentId] = [d].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_on_derived_with_filter1(bool async) @@ -638,20 +638,20 @@ public override async Task Include_reference_with_inheritance_on_derived_with_fi await base.Include_reference_with_inheritance_on_derived_with_filter1(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[BaseParentId], [t].[Name], [t].[Discriminator] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d1] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [d].[Name] <> N'Bar' OR [d].[Name] IS NULL -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_on_derived_with_filter2(bool async) @@ -659,20 +659,20 @@ public override async Task Include_reference_with_inheritance_on_derived_with_fi await base.Include_reference_with_inheritance_on_derived_with_filter2(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedInheritanceRelationshipEntityId], [t0].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[BaseParentId], [t].[Name], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedInheritanceRelationshipEntityId], N'BaseReferenceOnDerived' AS [Discriminator] FROM [BaseReferencesOnDerived] AS [b] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedInheritanceRelationshipEntityId], N'DerivedReferenceOnDerived' AS [Discriminator] - FROM [DerivedReferencesOnDerived] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedInheritanceRelationshipEntityId], N'DerivedReferenceOnDerived' AS [Discriminator] + FROM [DerivedReferencesOnDerived] AS [d1] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [d].[Name] <> N'Bar' OR [d].[Name] IS NULL -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_on_derived_with_filter4(bool async) @@ -695,20 +695,20 @@ public override async Task Include_reference_with_inheritance_on_derived_with_fi await base.Include_reference_with_inheritance_on_derived_with_filter_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator], [d0].[Id], [d0].[Name], [d0].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator], [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedInheritanceRelationshipEntityId], N'BaseReferenceOnDerived' AS [Discriminator] FROM [BaseReferencesOnDerived] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedInheritanceRelationshipEntityId], N'DerivedReferenceOnDerived' AS [Discriminator] - FROM [DerivedReferencesOnDerived] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedInheritanceRelationshipEntityId], N'DerivedReferenceOnDerived' AS [Discriminator] + FROM [DerivedReferencesOnDerived] AS [d1] ) AS [t] -LEFT JOIN [DerivedEntities] AS [d0] ON [t].[BaseParentId] = [d0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [d0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [OwnedCollections] AS [o0] ON [d0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities] AS [d] ON [t].[BaseParentId] = [d].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_reverse(bool async) @@ -716,32 +716,32 @@ public override async Task Include_reference_with_inheritance_reverse(bool async await base.Include_reference_with_inheritance_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t0].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t0].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_with_filter(bool async) @@ -749,33 +749,33 @@ public override async Task Include_reference_with_inheritance_with_filter(bool a await base.Include_reference_with_inheritance_with_filter(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d0] + SELECT [d2].[Id], [d2].[BaseParentId], [d2].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d2] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_with_filter_reverse(bool async) @@ -783,33 +783,33 @@ public override async Task Include_reference_with_inheritance_with_filter_revers await base.Include_reference_with_inheritance_with_filter_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t0].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t0].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_self_reference_with_inheritance(bool async) @@ -817,29 +817,29 @@ public override async Task Include_self_reference_with_inheritance(bool async) await base.Include_self_reference_with_inheritance(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [o1].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [d0].[Name], [d0].[BaseId], [o2].[BaseInheritanceRelationshipEntityId], [o2].[Id], [o2].[Name], [o0].[Id], [o0].[Name], [d3].[DerivedInheritanceRelationshipEntityId], [d3].[Id], [d3].[Name], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [d].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [o1].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [d].[Name], [d].[BaseId], [o2].[BaseInheritanceRelationshipEntityId], [o2].[Id], [o2].[Name], [o0].[Id], [o0].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d3].[Id], [d3].[Name], [d3].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d3] ) AS [t] -LEFT JOIN [DerivedEntities] AS [d0] ON [t].[Id] = [d0].[BaseId] +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[BaseId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d0] + WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -LEFT JOIN [OwnedReferences] AS [o0] ON [d0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [OwnedReferences] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o1] ON [t].[Id] = [o1].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -LEFT JOIN [OwnedCollections] AS [o2] ON [d0].[Id] = [o2].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d3] ON [d0].[Id] = [d3].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [o2].[BaseInheritanceRelationshipEntityId], [o2].[Id], [d3].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [OwnedCollections] AS [o2] ON [d].[Id] = [o2].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [d].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [o2].[BaseInheritanceRelationshipEntityId], [o2].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_self_reference_with_inheritance_reverse(bool async) @@ -847,29 +847,29 @@ public override async Task Include_self_reference_with_inheritance_reverse(bool await base.Include_self_reference_with_inheritance_reverse(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [o1].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o2].[BaseInheritanceRelationshipEntityId], [o2].[Id], [o2].[Name], [o0].[Id], [o0].[Name], [d3].[DerivedInheritanceRelationshipEntityId], [d3].[Id], [d3].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [o1].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[Name], [t].[BaseId], [t].[Discriminator], [o2].[BaseInheritanceRelationshipEntityId], [o2].[Id], [o2].[Name], [o0].[Id], [o0].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] -) AS [t0] ON [d].[BaseId] = [t0].[Id] + SELECT [d3].[Id], [d3].[Name], [d3].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d3] +) AS [t] ON [d].[BaseId] = [t].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [OwnedReferences] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [OwnedReferences] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] + SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d0] + WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o1] ON [d].[Id] = [o1].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [d].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -LEFT JOIN [OwnedCollections] AS [o2] ON [t0].[Id] = [o2].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d3] ON [t0].[Id] = [d3].[DerivedInheritanceRelationshipEntityId] -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [o2].[BaseInheritanceRelationshipEntityId], [o2].[Id], [d3].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [OwnedCollections] AS [o2] ON [t].[Id] = [o2].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [o2].[BaseInheritanceRelationshipEntityId], [o2].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_collection_reference_on_non_entity_base(bool async) @@ -892,42 +892,42 @@ public override async Task Nested_include_with_inheritance_collection_collection await base.Nested_include_with_inheritance_collection_collection(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [t2].[Id], [t2].[BaseParentId], [t2].[Name], [t2].[DerivedProperty], [t2].[Discriminator], [t2].[Id0], [t2].[Name0], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[Discriminator0] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator], [t1].[Id0], [t1].[Name0], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator0] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator], [t3].[Id] AS [Id0], [t3].[Name] AS [Name0], [t3].[ParentCollectionId], [t3].[ParentReferenceId], [t3].[Discriminator] AS [Discriminator0] + SELECT [t2].[Id], [t2].[BaseParentId], [t2].[Name], [t2].[DerivedProperty], [t2].[Discriminator], [t3].[Id] AS [Id0], [t3].[Name] AS [Name0], [t3].[ParentCollectionId], [t3].[ParentReferenceId], [t3].[Discriminator] AS [Discriminator0] FROM ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b0] UNION ALL SELECT [d2].[Id], [d2].[BaseParentId], [d2].[Name], [d2].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] FROM [DerivedCollectionsOnBase] AS [d2] - ) AS [t1] + ) AS [t2] LEFT JOIN ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedCollectionDerived' AS [Discriminator] FROM [NestedCollectionsDerived] AS [n0] - ) AS [t3] ON [t1].[Id] = [t3].[ParentCollectionId] -) AS [t2] ON [t].[Id] = [t2].[BaseParentId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [t2].[Id]"); + ) AS [t3] ON [t2].[Id] = [t3].[ParentCollectionId] +) AS [t1] ON [t].[Id] = [t1].[BaseParentId] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [t1].[Id]"); } public override async Task Nested_include_with_inheritance_collection_collection_reverse(bool async) @@ -935,7 +935,7 @@ public override async Task Nested_include_with_inheritance_collection_collection await base.Nested_include_with_inheritance_collection_collection_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t2].[Id], [t2].[Name], [t2].[BaseId], [t2].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t4].[OwnedReferenceOnDerived_Id], [t4].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] @@ -947,27 +947,27 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] + FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t0] ON [t].[ParentCollectionId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -LEFT JOIN [OwnedCollections] AS [o0] ON [t2].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t2].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_collection_reference(bool async) @@ -975,42 +975,42 @@ public override async Task Nested_include_with_inheritance_collection_reference( await base.Nested_include_with_inheritance_collection_reference(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [t2].[Id], [t2].[BaseParentId], [t2].[Name], [t2].[DerivedProperty], [t2].[Discriminator], [t2].[Id0], [t2].[Name0], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[Discriminator0] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator], [t1].[Id0], [t1].[Name0], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator0] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator], [t3].[Id] AS [Id0], [t3].[Name] AS [Name0], [t3].[ParentCollectionId], [t3].[ParentReferenceId], [t3].[Discriminator] AS [Discriminator0] + SELECT [t2].[Id], [t2].[BaseParentId], [t2].[Name], [t2].[DerivedProperty], [t2].[Discriminator], [t3].[Id] AS [Id0], [t3].[Name] AS [Name0], [t3].[ParentCollectionId], [t3].[ParentReferenceId], [t3].[Discriminator] AS [Discriminator0] FROM ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b0] UNION ALL SELECT [d2].[Id], [d2].[BaseParentId], [d2].[Name], [d2].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] FROM [DerivedCollectionsOnBase] AS [d2] - ) AS [t1] + ) AS [t2] LEFT JOIN ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] FROM [NestedReferences] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedReferenceDerived' AS [Discriminator] FROM [NestedReferencesDerived] AS [n0] - ) AS [t3] ON [t1].[Id] = [t3].[ParentCollectionId] -) AS [t2] ON [t].[Id] = [t2].[BaseParentId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [t2].[Id]"); + ) AS [t3] ON [t2].[Id] = [t3].[ParentCollectionId] +) AS [t1] ON [t].[Id] = [t1].[BaseParentId] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [t1].[Id]"); } public override async Task Nested_include_with_inheritance_collection_reference_reverse(bool async) @@ -1018,7 +1018,7 @@ public override async Task Nested_include_with_inheritance_collection_reference_ await base.Nested_include_with_inheritance_collection_reference_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t2].[Id], [t2].[Name], [t2].[BaseId], [t2].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t4].[OwnedReferenceOnDerived_Id], [t4].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] FROM [NestedReferences] AS [n] @@ -1030,27 +1030,27 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] + FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t0] ON [t].[ParentCollectionId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -LEFT JOIN [OwnedCollections] AS [o0] ON [t2].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t2].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_reference_collection(bool async) @@ -1058,39 +1058,39 @@ public override async Task Nested_include_with_inheritance_reference_collection( await base.Nested_include_with_inheritance_reference_collection(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t3].[Id], [t3].[Name], [t3].[ParentCollectionId], [t3].[ParentReferenceId], [t3].[Discriminator] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t2].[Id], [t2].[Name], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[Discriminator] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d0] + SELECT [d2].[Id], [d2].[BaseParentId], [d2].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d2] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedCollectionDerived' AS [Discriminator] FROM [NestedCollectionsDerived] AS [n0] -) AS [t3] ON [t0].[Id] = [t3].[ParentReferenceId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id]"); +) AS [t2] ON [t0].[Id] = [t2].[ParentReferenceId] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Nested_include_with_inheritance_reference_collection_on_base(bool async) @@ -1098,26 +1098,26 @@ public override async Task Nested_include_with_inheritance_reference_collection_ await base.Nested_include_with_inheritance_reference_collection_on_base(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t1].[Id], [t1].[Name], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[ParentCollectionId], [t0].[ParentReferenceId], [t0].[Discriminator] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d1] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedCollectionDerived' AS [Discriminator] FROM [NestedCollectionsDerived] AS [n0] -) AS [t1] ON [t0].[Id] = [t1].[ParentReferenceId] -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id]"); +) AS [t0] ON [t].[Id] = [t0].[ParentReferenceId] +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Nested_include_with_inheritance_reference_collection_reverse(bool async) @@ -1125,7 +1125,7 @@ public override async Task Nested_include_with_inheritance_reference_collection_ await base.Nested_include_with_inheritance_reference_collection_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t2].[Id], [t2].[Name], [t2].[BaseId], [t2].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t4].[OwnedReferenceOnDerived_Id], [t4].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] @@ -1137,27 +1137,27 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d1] ) AS [t0] ON [t].[ParentReferenceId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] -END -LEFT JOIN [OwnedCollections] AS [o0] ON [t2].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t2].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] +END +LEFT JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_reference_reference(bool async) @@ -1165,20 +1165,20 @@ public override async Task Nested_include_with_inheritance_reference_reference(b await base.Nested_include_with_inheritance_reference_reference(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t4].[OwnedReferenceOnDerived_Id], [t4].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t2].[Name], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[Discriminator] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t1].[Name], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d0] + SELECT [d2].[Id], [d2].[BaseParentId], [d2].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d2] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] LEFT JOIN ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] @@ -1186,18 +1186,18 @@ FROM [NestedReferences] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedReferenceDerived' AS [Discriminator] FROM [NestedReferencesDerived] AS [n0] -) AS [t2] ON [t0].[Id] = [t2].[ParentReferenceId] +) AS [t1] ON [t0].[Id] = [t1].[ParentReferenceId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_reference_reference_on_base(bool async) @@ -1205,26 +1205,26 @@ public override async Task Nested_include_with_inheritance_reference_reference_o await base.Nested_include_with_inheritance_reference_reference_on_base(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t1].[Name], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Name], [t0].[ParentCollectionId], [t0].[ParentReferenceId], [t0].[Discriminator] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d1] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] FROM [NestedReferences] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedReferenceDerived' AS [Discriminator] FROM [NestedReferencesDerived] AS [n0] -) AS [t1] ON [t0].[Id] = [t1].[ParentReferenceId] +) AS [t0] ON [t].[Id] = [t0].[ParentReferenceId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [d].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [d].[Id], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_reference_reference_reverse(bool async) @@ -1232,7 +1232,7 @@ public override async Task Nested_include_with_inheritance_reference_reference_r await base.Nested_include_with_inheritance_reference_reference_reverse(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t2].[Id], [t2].[Name], [t2].[BaseId], [t2].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t4].[OwnedReferenceOnDerived_Id], [t4].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] FROM [NestedReferences] AS [n] @@ -1244,27 +1244,27 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d1] ) AS [t0] ON [t].[ParentReferenceId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -LEFT JOIN [OwnedCollections] AS [o0] ON [t2].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t2].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d2].[DerivedInheritanceRelationshipEntityId]"); +LEFT JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Collection_projection_on_base_type(bool async) @@ -1295,27 +1295,27 @@ public override async Task Include_on_derived_type_with_queryable_Cast(bool asyn await base.Include_on_derived_type_with_queryable_Cast(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [d2].[Id], [d2].[Name], [d2].[ParentId], [d2].[DerivedInheritanceRelationshipEntityId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [d1].[Id], [d1].[Name], [d1].[ParentId], [d1].[DerivedInheritanceRelationshipEntityId] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d2].[Id], [d2].[Name], [d2].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d2] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -LEFT JOIN [DerivedCollectionsOnDerived] AS [d2] ON [t].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +LEFT JOIN [DerivedCollectionsOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Id] >= 4 -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_with_inheritance_split(bool async) @@ -1328,14 +1328,14 @@ public override async Task Include_collection_with_inheritance_split(bool async) SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1346,37 +1346,37 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // @"SELECT [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] @@ -1384,14 +1384,14 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1410,82 +1410,82 @@ public override async Task Include_collection_with_inheritance_reverse_split(boo await base.Include_collection_with_inheritance_reverse_split(async); AssertSql( - @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o].[Id], [o].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o].[Id], [o].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] + FROM [DerivedCollectionsOnBase] AS [d0] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] FROM ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId] + FROM [DerivedCollectionsOnBase] AS [d0] ) AS [t] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END INNER JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", // - @"SELECT [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] FROM ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId] + FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] + SELECT [d2].[Id] + FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t0].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]"); +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t0].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]"); } public override async Task Include_collection_with_inheritance_with_filter_split(bool async) @@ -1498,14 +1498,14 @@ public override async Task Include_collection_with_inheritance_with_filter_split SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1517,14 +1517,14 @@ WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1532,23 +1532,23 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM ( SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // @@ -1557,14 +1557,14 @@ WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1584,85 +1584,85 @@ public override async Task Include_collection_with_inheritance_with_filter_rever await base.Include_collection_with_inheritance_with_filter_reverse_split(async); AssertSql( - @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o].[Id], [o].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o].[Id], [o].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] + FROM [DerivedCollectionsOnBase] AS [d0] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d1] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name] + FROM [DerivedCollectionsOnBase] AS [d0] ) AS [t] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END INNER JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", // - @"SELECT [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name] + FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] + SELECT [d2].[Id] + FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t0].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t0].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t0].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t0].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]"); } public override async Task Include_collection_without_inheritance_split(bool async) @@ -1675,14 +1675,14 @@ public override async Task Include_collection_without_inheritance_split(bool asy SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1693,37 +1693,37 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] @@ -1731,14 +1731,14 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1751,64 +1751,64 @@ public override async Task Include_collection_without_inheritance_reverse_split( await base.Include_collection_without_inheritance_reverse_split(async); AssertSql( - @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o].[Id], [o].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [c].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] +) AS [t] ON [c].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -ORDER BY [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [c].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] + SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] +) AS [t] ON [c].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", +INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [c].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] +) AS [t] ON [c].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]"); +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); } public override async Task Include_collection_without_inheritance_with_filter_split(bool async) @@ -1821,14 +1821,14 @@ public override async Task Include_collection_without_inheritance_with_filter_sp SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1840,14 +1840,14 @@ WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1855,23 +1855,23 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM ( SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id], [d1].[Name] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // @@ -1880,14 +1880,14 @@ WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -1901,67 +1901,67 @@ public override async Task Include_collection_without_inheritance_with_filter_re await base.Include_collection_without_inheritance_with_filter_reverse_split(async); AssertSql( - @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o].[Id], [o].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [c].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] +) AS [t] ON [c].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END WHERE [c].[Name] <> N'Bar' OR [c].[Name] IS NULL -ORDER BY [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [c].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] + SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] +) AS [t] ON [c].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] WHERE [c].[Name] <> N'Bar' OR [c].[Name] IS NULL -ORDER BY [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] -) AS [t0] ON [c].[ParentId] = [t0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t0].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] +) AS [t] ON [c].[ParentId] = [t].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t0] ON [t].[Id] = CASE + WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [c].[Name] <> N'Bar' OR [c].[Name] IS NULL -ORDER BY [c].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]"); +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); } public override async Task Include_collection_with_inheritance_on_derived1_split(bool async) @@ -1986,7 +1986,7 @@ FROM [DerivedEntities] AS [d] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", // - @"SELECT [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN ( @@ -1995,7 +1995,7 @@ FROM [BaseCollectionsOnBase] AS [b] UNION ALL SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] FROM [DerivedCollectionsOnBase] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] +) AS [t] ON [d].[Id] = [t].[BaseParentId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]"); } @@ -2020,7 +2020,7 @@ FROM [DerivedEntities] AS [d] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", // - @"SELECT [t0].[Id], [t0].[Name], [t0].[ParentId], [t0].[DerivedInheritanceRelationshipEntityId], [t0].[Discriminator], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] + @"SELECT [t].[Id], [t].[Name], [t].[ParentId], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN ( @@ -2029,7 +2029,7 @@ FROM [BaseCollectionsOnDerived] AS [b] UNION ALL SELECT [d0].[Id], [d0].[Name], [d0].[ParentId], [d0].[DerivedInheritanceRelationshipEntityId], N'DerivedCollectionOnDerived' AS [Discriminator] FROM [DerivedCollectionsOnDerived] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[ParentId] +) AS [t] ON [d].[Id] = [t].[ParentId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]"); } @@ -2067,43 +2067,43 @@ public override async Task Include_collection_with_inheritance_on_derived_revers await base.Include_collection_with_inheritance_on_derived_reverse_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[ParentId], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator], [d0].[Id], [d0].[Name], [d0].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[ParentId], [t].[DerivedInheritanceRelationshipEntityId], [t].[Discriminator], [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], [b].[ParentId], NULL AS [DerivedInheritanceRelationshipEntityId], N'BaseCollectionOnDerived' AS [Discriminator] FROM [BaseCollectionsOnDerived] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[ParentId], [d].[DerivedInheritanceRelationshipEntityId], N'DerivedCollectionOnDerived' AS [Discriminator] - FROM [DerivedCollectionsOnDerived] AS [d] + SELECT [d0].[Id], [d0].[Name], [d0].[ParentId], [d0].[DerivedInheritanceRelationshipEntityId], N'DerivedCollectionOnDerived' AS [Discriminator] + FROM [DerivedCollectionsOnDerived] AS [d0] ) AS [t] -LEFT JOIN [DerivedEntities] AS [d0] ON [t].[ParentId] = [d0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [d0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId]", +LEFT JOIN [DerivedEntities] AS [d] ON [t].[ParentId] = [d].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM ( SELECT [b].[Id], [b].[ParentId] FROM [BaseCollectionsOnDerived] AS [b] UNION ALL - SELECT [d].[Id], [d].[ParentId] - FROM [DerivedCollectionsOnDerived] AS [d] + SELECT [d0].[Id], [d0].[ParentId] + FROM [DerivedCollectionsOnDerived] AS [d0] ) AS [t] -LEFT JOIN [DerivedEntities] AS [d0] ON [t].[ParentId] = [d0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [d0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -INNER JOIN [OwnedCollections] AS [o0] ON [d0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId]", +LEFT JOIN [DerivedEntities] AS [d] ON [t].[ParentId] = [d].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] +INNER JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM ( SELECT [b].[Id], [b].[ParentId] FROM [BaseCollectionsOnDerived] AS [b] UNION ALL - SELECT [d].[Id], [d].[ParentId] - FROM [DerivedCollectionsOnDerived] AS [d] + SELECT [d1].[Id], [d1].[ParentId] + FROM [DerivedCollectionsOnDerived] AS [d1] ) AS [t] -LEFT JOIN [DerivedEntities] AS [d0] ON [t].[ParentId] = [d0].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [d0].[Id] = [o].[BaseInheritanceRelationshipEntityId] -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d0].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId]"); +LEFT JOIN [DerivedEntities] AS [d] ON [t].[ParentId] = [d].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_reference_collection_split(bool async) @@ -2111,105 +2111,105 @@ public override async Task Nested_include_with_inheritance_reference_collection_ await base.Nested_include_with_inheritance_reference_collection_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o].[Id], [o].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o].[Id], [o].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d0] + SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d1] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId] FROM [BaseReferencesOnBase] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId] - FROM [DerivedReferencesOnBase] AS [d0] + SELECT [d1].[Id], [d1].[BaseParentId] + FROM [DerivedReferencesOnBase] AS [d1] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", // - @"SELECT [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId] FROM [BaseReferencesOnBase] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId] - FROM [DerivedReferencesOnBase] AS [d0] + SELECT [d2].[Id], [d2].[BaseParentId] + FROM [DerivedReferencesOnBase] AS [d2] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", // - @"SELECT [t3].[Id], [t3].[Name], [t3].[ParentCollectionId], [t3].[ParentReferenceId], [t3].[Discriminator], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] + @"SELECT [t2].[Id], [t2].[Name], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[Discriminator], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN ( SELECT [b0].[Id], [b0].[BaseParentId] FROM [BaseReferencesOnBase] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId] - FROM [DerivedReferencesOnBase] AS [d0] + SELECT [d1].[Id], [d1].[BaseParentId] + FROM [DerivedReferencesOnBase] AS [d1] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t2] ON [t].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t1] ON [t].[Id] = CASE + WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] END INNER JOIN ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] @@ -2217,8 +2217,8 @@ FROM [NestedCollections] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedCollectionDerived' AS [Discriminator] FROM [NestedCollectionsDerived] AS [n0] -) AS [t3] ON [t0].[Id] = [t3].[ParentReferenceId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]"); +) AS [t2] ON [t0].[Id] = [t2].[ParentReferenceId] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]"); } public override async Task Nested_include_with_inheritance_reference_collection_on_base_split(bool async) @@ -2226,7 +2226,7 @@ public override async Task Nested_include_with_inheritance_reference_collection_ await base.Nested_include_with_inheritance_reference_collection_on_base_split(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[BaseParentId], [t].[Name], [t].[Discriminator] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] @@ -2234,11 +2234,11 @@ FROM [BaseReferencesOnBase] AS [b] UNION ALL SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] FROM [DerivedReferencesOnBase] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId]", +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] @@ -2246,25 +2246,25 @@ FROM [BaseReferencesOnBase] AS [b] UNION ALL SELECT [d0].[Id], [d0].[BaseParentId] FROM [DerivedReferencesOnBase] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId]", +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d0].[Id], [d0].[BaseParentId] - FROM [DerivedReferencesOnBase] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] + SELECT [d1].[Id], [d1].[BaseParentId] + FROM [DerivedReferencesOnBase] AS [d1] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [d].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId]", +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId]", // - @"SELECT [t1].[Id], [t1].[Name], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator], [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId] + @"SELECT [t0].[Id], [t0].[Name], [t0].[ParentCollectionId], [t0].[ParentReferenceId], [t0].[Discriminator], [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] @@ -2272,7 +2272,7 @@ FROM [BaseReferencesOnBase] AS [b] UNION ALL SELECT [d0].[Id], [d0].[BaseParentId] FROM [DerivedReferencesOnBase] AS [d0] -) AS [t0] ON [d].[Id] = [t0].[BaseParentId] +) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] @@ -2280,8 +2280,8 @@ FROM [NestedCollections] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedCollectionDerived' AS [Discriminator] FROM [NestedCollectionsDerived] AS [n0] -) AS [t1] ON [t0].[Id] = [t1].[ParentReferenceId] -ORDER BY [d].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId]"); +) AS [t0] ON [t].[Id] = [t0].[ParentReferenceId] +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_reference_collection_reverse_split(bool async) @@ -2289,7 +2289,7 @@ public override async Task Nested_include_with_inheritance_reference_collection_ await base.Nested_include_with_inheritance_reference_collection_reverse_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t2].[Id], [t2].[Name], [t2].[BaseId], [t2].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o].[Id], [o].[Name], [t4].[OwnedReferenceOnDerived_Id], [t4].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o].[Id], [o].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] @@ -2301,27 +2301,27 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], N'DerivedReferenceOnBase' AS [Discriminator] - FROM [DerivedReferencesOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], N'DerivedReferenceOnBase' AS [Discriminator] + FROM [DerivedReferencesOnBase] AS [d0] ) AS [t0] ON [t].[ParentReferenceId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id]", +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] FROM ( SELECT [n].[Id], [n].[ParentReferenceId] FROM [NestedCollections] AS [n] @@ -2333,28 +2333,28 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId] - FROM [DerivedReferencesOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId] + FROM [DerivedReferencesOnBase] AS [d0] ) AS [t0] ON [t].[ParentReferenceId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] + SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -INNER JOIN [OwnedCollections] AS [o0] ON [t2].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id]", +INNER JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", // - @"SELECT [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] FROM ( SELECT [n].[Id], [n].[ParentReferenceId] FROM [NestedCollections] AS [n] @@ -2366,26 +2366,26 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseReferencesOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId] - FROM [DerivedReferencesOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId] + FROM [DerivedReferencesOnBase] AS [d1] ) AS [t0] ON [t].[ParentReferenceId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d2].[Id] + FROM [DerivedEntities] AS [d2] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t2].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id]"); +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]"); } public override async Task Nested_include_with_inheritance_collection_reference_split(bool async) @@ -2398,14 +2398,14 @@ public override async Task Nested_include_with_inheritance_collection_reference_ SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -2416,72 +2416,72 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [t2].[Id], [t2].[BaseParentId], [t2].[Name], [t2].[DerivedProperty], [t2].[Discriminator], [t2].[Id0], [t2].[Name0], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[Discriminator0] AS [Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] + @"SELECT [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator], [t1].[Id0], [t1].[Name0], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator0] AS [Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END INNER JOIN ( - SELECT [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator], [t3].[Id] AS [Id0], [t3].[Name] AS [Name0], [t3].[ParentCollectionId], [t3].[ParentReferenceId], [t3].[Discriminator] AS [Discriminator0] + SELECT [t2].[Id], [t2].[BaseParentId], [t2].[Name], [t2].[DerivedProperty], [t2].[Discriminator], [t3].[Id] AS [Id0], [t3].[Name] AS [Name0], [t3].[ParentCollectionId], [t3].[ParentReferenceId], [t3].[Discriminator] AS [Discriminator0] FROM ( SELECT [b0].[Id], [b0].[BaseParentId], [b0].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b0] UNION ALL SELECT [d1].[Id], [d1].[BaseParentId], [d1].[Name], [d1].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] FROM [DerivedCollectionsOnBase] AS [d1] - ) AS [t1] + ) AS [t2] LEFT JOIN ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] FROM [NestedReferences] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedReferenceDerived' AS [Discriminator] FROM [NestedReferencesDerived] AS [n0] - ) AS [t3] ON [t1].[Id] = [t3].[ParentCollectionId] -) AS [t2] ON [t].[Id] = [t2].[BaseParentId] + ) AS [t3] ON [t2].[Id] = [t3].[ParentCollectionId] +) AS [t1] ON [t].[Id] = [t1].[BaseParentId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); } @@ -2490,7 +2490,7 @@ public override async Task Nested_include_with_inheritance_collection_reference_ await base.Nested_include_with_inheritance_collection_reference_reverse_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t2].[Id], [t2].[Name], [t2].[BaseId], [t2].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o].[Id], [o].[Name], [t4].[OwnedReferenceOnDerived_Id], [t4].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o].[Id], [o].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] FROM [NestedReferences] AS [n] @@ -2502,27 +2502,27 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] + FROM [DerivedCollectionsOnBase] AS [d0] ) AS [t0] ON [t].[ParentCollectionId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id]", +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] FROM ( SELECT [n].[Id], [n].[ParentCollectionId] FROM [NestedReferences] AS [n] @@ -2534,28 +2534,28 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId] + FROM [DerivedCollectionsOnBase] AS [d0] ) AS [t0] ON [t].[ParentCollectionId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] + SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -INNER JOIN [OwnedCollections] AS [o0] ON [t2].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id]", +INNER JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", // - @"SELECT [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] FROM ( SELECT [n].[Id], [n].[ParentCollectionId] FROM [NestedReferences] AS [n] @@ -2567,26 +2567,26 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId] + FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t0] ON [t].[ParentCollectionId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d2].[Id] + FROM [DerivedEntities] AS [d2] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t2].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id]"); +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]"); } public override async Task Nested_include_with_inheritance_collection_collection_split(bool async) @@ -2599,14 +2599,14 @@ public override async Task Nested_include_with_inheritance_collection_collection SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -2617,37 +2617,37 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // @"SELECT [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] @@ -2655,14 +2655,14 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -2675,19 +2675,19 @@ FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t1] ON [t].[Id] = [t1].[BaseParentId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [t1].[Id]", // - @"SELECT [t3].[Id], [t3].[Name], [t3].[ParentCollectionId], [t3].[ParentReferenceId], [t3].[Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [t1].[Id] + @"SELECT [t2].[Id], [t2].[Name], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [t1].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -2704,7 +2704,7 @@ FROM [NestedCollections] AS [n] UNION ALL SELECT [n0].[Id], [n0].[Name], [n0].[ParentCollectionId], [n0].[ParentReferenceId], N'NestedCollectionDerived' AS [Discriminator] FROM [NestedCollectionsDerived] AS [n0] -) AS [t3] ON [t1].[Id] = [t3].[ParentCollectionId] +) AS [t2] ON [t1].[Id] = [t2].[ParentCollectionId] ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [t1].[Id]"); } @@ -2713,7 +2713,7 @@ public override async Task Nested_include_with_inheritance_collection_collection await base.Nested_include_with_inheritance_collection_collection_reverse_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t2].[Id], [t2].[Name], [t2].[BaseId], [t2].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id], [o].[Id], [o].[Name], [t4].[OwnedReferenceOnDerived_Id], [t4].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[ParentCollectionId], [t].[ParentReferenceId], [t].[Discriminator], [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o].[Id], [o].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] @@ -2725,27 +2725,27 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId], [d].[Name], [d].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedProperty], N'DerivedCollectionOnBase' AS [Discriminator] + FROM [DerivedCollectionsOnBase] AS [d0] ) AS [t0] ON [t].[ParentCollectionId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id], [d1].[OwnedReferenceOnDerived_Name] + SELECT [d1].[Id], [d1].[Name], [d1].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id]", +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id] + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] FROM ( SELECT [n].[Id], [n].[ParentCollectionId] FROM [NestedCollections] AS [n] @@ -2757,28 +2757,28 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d0].[Id], [d0].[BaseParentId] + FROM [DerivedCollectionsOnBase] AS [d0] ) AS [t0] ON [t].[ParentCollectionId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] + SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] +LEFT JOIN ( + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -INNER JOIN [OwnedCollections] AS [o0] ON [t2].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id]", +INNER JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", // - @"SELECT [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] FROM ( SELECT [n].[Id], [n].[ParentCollectionId] FROM [NestedCollections] AS [n] @@ -2790,26 +2790,26 @@ LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseCollectionsOnBase] AS [b] UNION ALL - SELECT [d].[Id], [d].[BaseParentId] - FROM [DerivedCollectionsOnBase] AS [d] + SELECT [d1].[Id], [d1].[BaseParentId] + FROM [DerivedCollectionsOnBase] AS [d1] ) AS [t0] ON [t].[ParentCollectionId] = [t0].[Id] LEFT JOIN ( SELECT [b0].[Id] FROM [BaseEntities] AS [b0] UNION ALL - SELECT [d0].[Id] - FROM [DerivedEntities] AS [d0] -) AS [t2] ON [t0].[BaseParentId] = [t2].[Id] -LEFT JOIN [OwnedReferences] AS [o] ON [t2].[Id] = [o].[BaseInheritanceRelationshipEntityId] + SELECT [d2].[Id] + FROM [DerivedEntities] AS [d2] +) AS [t1] ON [t0].[BaseParentId] = [t1].[Id] +LEFT JOIN [OwnedReferences] AS [o] ON [t1].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d1].[Id], [d1].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d1] - WHERE [d1].[OwnedReferenceOnDerived_Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = CASE - WHEN [t4].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t4].[Id] + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL +) AS [t2] ON [t1].[Id] = CASE + WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d2] ON [t2].[Id] = [d2].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t2].[Id], [o].[BaseInheritanceRelationshipEntityId], [t4].[Id]"); +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]"); } public override async Task Nested_include_collection_reference_on_non_entity_base_split(bool async) @@ -2874,14 +2874,14 @@ public override async Task Include_on_derived_type_with_queryable_Cast_split(boo SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id], [d].[Name], [d].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id], [d0].[Name], [d0].[BaseId], N'DerivedInheritanceRelationshipEntity' AS [Discriminator] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -2893,14 +2893,14 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d0].[Id] + FROM [DerivedEntities] AS [d0] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END @@ -2908,43 +2908,43 @@ WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] WHERE [t].[Id] >= 4 ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Id] >= 4 ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", // - @"SELECT [d1].[Id], [d1].[Name], [d1].[ParentId], [d1].[DerivedInheritanceRelationshipEntityId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] + @"SELECT [d0].[Id], [d0].[Name], [d0].[ParentId], [d0].[DerivedInheritanceRelationshipEntityId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] UNION ALL - SELECT [d].[Id] - FROM [DerivedEntities] AS [d] + SELECT [d1].[Id] + FROM [DerivedEntities] AS [d1] ) AS [t] LEFT JOIN [OwnedReferences] AS [o] ON [t].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN ( - SELECT [d0].[Id], [d0].[OwnedReferenceOnDerived_Id] - FROM [DerivedEntities] AS [d0] - WHERE [d0].[OwnedReferenceOnDerived_Id] IS NOT NULL + SELECT [d].[Id], [d].[OwnedReferenceOnDerived_Id] + FROM [DerivedEntities] AS [d] + WHERE [d].[OwnedReferenceOnDerived_Id] IS NOT NULL ) AS [t0] ON [t].[Id] = CASE WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] END -INNER JOIN [DerivedCollectionsOnDerived] AS [d1] ON [t].[Id] = [d1].[DerivedInheritanceRelationshipEntityId] +INNER JOIN [DerivedCollectionsOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Id] >= 4 ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs index 2ca24164a55..4dbf65492b1 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs @@ -1937,11 +1937,9 @@ public override async Task Concat_scalars_with_count(bool async) FROM ( SELECT [g].[Nickname] FROM [Gears] AS [g] - LEFT JOIN [Officers] AS [o] ON [g].[Nickname] = [o].[Nickname] AND [g].[SquadId] = [o].[SquadId] UNION ALL SELECT [g0].[FullName] AS [Nickname] FROM [Gears] AS [g0] - LEFT JOIN [Officers] AS [o0] ON [g0].[Nickname] = [o0].[Nickname] AND [g0].[SquadId] = [o0].[SquadId] ) AS [t]"); } @@ -1971,20 +1969,11 @@ public override async Task Concat_with_scalar_projection(bool async) await base.Concat_with_scalar_projection(async); AssertSql( - @"SELECT [t].[Nickname] -FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank], CASE - WHEN [o].[Nickname] IS NOT NULL THEN N'Officer' - END AS [Discriminator] - FROM [Gears] AS [g] - LEFT JOIN [Officers] AS [o] ON [g].[Nickname] = [o].[Nickname] AND [g].[SquadId] = [o].[SquadId] - UNION ALL - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank], CASE - WHEN [o0].[Nickname] IS NOT NULL THEN N'Officer' - END AS [Discriminator] - FROM [Gears] AS [g0] - LEFT JOIN [Officers] AS [o0] ON [g0].[Nickname] = [o0].[Nickname] AND [g0].[SquadId] = [o0].[SquadId] -) AS [t]"); + @"SELECT [g].[Nickname] +FROM [Gears] AS [g] +UNION ALL +SELECT [g0].[Nickname] +FROM [Gears] AS [g0]"); } public override async Task Select_navigation_with_concat_and_count(bool async) @@ -7339,7 +7328,6 @@ SELECT COUNT(*) FROM [Weapons] AS [w] WHERE [g].[FullName] = [w].[OwnerFullName]) AS [Count] FROM [Gears] AS [g] - LEFT JOIN [Officers] AS [o] ON [g].[Nickname] = [o].[Nickname] AND [g].[SquadId] = [o].[SquadId] LEFT JOIN [Cities] AS [c] ON [g].[AssignedCityName] = [c].[Name] UNION ALL SELECT [c0].[Name], ( @@ -7347,7 +7335,6 @@ SELECT COUNT(*) FROM [Weapons] AS [w0] WHERE [g0].[FullName] = [w0].[OwnerFullName]) AS [Count] FROM [Gears] AS [g0] - LEFT JOIN [Officers] AS [o0] ON [g0].[Nickname] = [o0].[Nickname] AND [g0].[SquadId] = [o0].[SquadId] INNER JOIN [Cities] AS [c0] ON [g0].[CityOfBirthName] = [c0].[Name] ) AS [t] GROUP BY [t].[Name], [t].[Count]"); @@ -7365,7 +7352,6 @@ SELECT COUNT(*) FROM [Weapons] AS [w] WHERE [g].[FullName] = [w].[OwnerFullName]) AS [Count] FROM [Gears] AS [g] - LEFT JOIN [Officers] AS [o] ON [g].[Nickname] = [o].[Nickname] AND [g].[SquadId] = [o].[SquadId] LEFT JOIN [Cities] AS [c] ON [g].[AssignedCityName] = [c].[Name] UNION ALL SELECT [c0].[Name], ( @@ -7373,7 +7359,6 @@ SELECT COUNT(*) FROM [Weapons] AS [w0] WHERE [g0].[FullName] = [w0].[OwnerFullName]) AS [Count] FROM [Gears] AS [g0] - LEFT JOIN [Officers] AS [o0] ON [g0].[Nickname] = [o0].[Nickname] AND [g0].[SquadId] = [o0].[SquadId] INNER JOIN [Cities] AS [c0] ON [g0].[CityOfBirthName] = [c0].[Name] ) AS [t] GROUP BY [t].[Name], [t].[Count]"); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalGearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalGearsOfWarQuerySqlServerTest.cs index 6b74d3ac8f0..534be2fb092 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalGearsOfWarQuerySqlServerTest.cs @@ -6487,14 +6487,11 @@ public override async Task Concat_with_scalar_projection(bool async) await base.Concat_with_scalar_projection(async); AssertSql( - @"SELECT [t].[Nickname] -FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOfBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[PeriodEnd], [g].[PeriodStart], [g].[Rank] - FROM [Gears] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [g] - UNION ALL - SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOfBirthName], [g0].[Discriminator], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[PeriodEnd], [g0].[PeriodStart], [g0].[Rank] - FROM [Gears] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [g0] -) AS [t]"); + @"SELECT [g].[Nickname] +FROM [Gears] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [g] +UNION ALL +SELECT [g0].[Nickname] +FROM [Gears] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [g0]"); } public override async Task Correlated_collections_different_collections_projected(bool async) diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs index 8b5a38260b9..65edd9c7ec5 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs @@ -5179,14 +5179,11 @@ public override async Task Concat_with_scalar_projection(bool async) await base.Concat_with_scalar_projection(async); AssertSql( - @"SELECT ""t"".""Nickname"" -FROM ( - SELECT ""g"".""Nickname"", ""g"".""SquadId"", ""g"".""AssignedCityName"", ""g"".""CityOfBirthName"", ""g"".""Discriminator"", ""g"".""FullName"", ""g"".""HasSoulPatch"", ""g"".""LeaderNickname"", ""g"".""LeaderSquadId"", ""g"".""Rank"" - FROM ""Gears"" AS ""g"" - UNION ALL - SELECT ""g0"".""Nickname"", ""g0"".""SquadId"", ""g0"".""AssignedCityName"", ""g0"".""CityOfBirthName"", ""g0"".""Discriminator"", ""g0"".""FullName"", ""g0"".""HasSoulPatch"", ""g0"".""LeaderNickname"", ""g0"".""LeaderSquadId"", ""g0"".""Rank"" - FROM ""Gears"" AS ""g0"" -) AS ""t"""); + @"SELECT ""g"".""Nickname"" +FROM ""Gears"" AS ""g"" +UNION ALL +SELECT ""g0"".""Nickname"" +FROM ""Gears"" AS ""g0"""); } public override async Task Comparing_entities_using_Equals_inheritance(bool async)