From 8f20257de0a8c2739ff8c04cae5f3829a71e6018 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Mon, 12 Sep 2022 10:15:08 -0700 Subject: [PATCH] Query: Full support for entity splitting Resolves #620 --- .../RelationalEntityTypeExtensions.cs | 8 +- ...yableMethodTranslatingExpressionVisitor.cs | 357 +- .../Query/SqlExpressions/SelectExpression.cs | 325 +- .../Query/EntitySplittingQueryFixtureBase.cs | 70 - .../Query/EntitySplittingQueryTestBase.cs | 2917 ++++++++++++++++- .../EntitySplitting/EntitySplittingContext.cs | 2 - .../EntitySplitting/EntitySplittingData.cs | 220 ++ .../EntitySplitting/EntitySplittingTypes.cs | 110 + .../EntitySplitting/SplitEntityData.cs | 37 - .../EntitySplitting/SplitEntityOne.cs | 12 - .../EntitySplittingQuerySqlServerFixture.cs | 10 - .../EntitySplittingQuerySqlServerTest.cs | 709 +++- ...eritanceRelationshipsQuerySqlServerTest.cs | 32 +- .../Query/OwnedEntityQuerySqlServerTest.cs | 34 +- .../Query/OwnedQuerySqlServerTest.cs | 38 +- .../TPCRelationshipsQuerySqlServerTest.cs | 1190 ++----- .../TPTRelationshipsQuerySqlServerTest.cs | 168 +- .../Query/TemporalOwnedQuerySqlServerTest.cs | 86 +- .../Query/TemporalTableSqlServerTest.cs | 36 +- .../EntitySplittingQuerySqliteFixture.cs | 10 - .../Query/EntitySplittingQuerySqliteTest.cs | 354 +- 21 files changed, 5126 insertions(+), 1599 deletions(-) delete mode 100644 test/EFCore.Relational.Specification.Tests/Query/EntitySplittingQueryFixtureBase.cs create mode 100644 test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingData.cs create mode 100644 test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingTypes.cs delete mode 100644 test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/SplitEntityData.cs delete mode 100644 test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/SplitEntityOne.cs delete mode 100644 test/EFCore.SqlServer.FunctionalTests/Query/EntitySplittingQuerySqlServerFixture.cs delete mode 100644 test/EFCore.Sqlite.FunctionalTests/Query/EntitySplittingQuerySqliteFixture.cs diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalEntityTypeExtensions.cs b/src/EFCore.Relational/Metadata/Internal/RelationalEntityTypeExtensions.cs index 3d879b6dc43..366a39f2bd1 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalEntityTypeExtensions.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalEntityTypeExtensions.cs @@ -91,7 +91,13 @@ public static IEnumerable GetNonPrincipalSharedNonPkProperties(this I continue; } - var propertyMappings = table.FindColumn(property)!.PropertyMappings; + var column = table.FindColumn(property); + if (column == null) + { + continue; + } + + var propertyMappings = column.PropertyMappings; if (propertyMappings.Count() > 1 && propertyMappings.Any(pm => principalEntityTypes.Contains(pm.TableMapping.EntityType))) { diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index f118c68a2b8..2dc88ae1c9b 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -454,7 +454,7 @@ private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType ent { // This could be group by entity type if (remappedKeySelector is not EntityShaperExpression - { ValueBufferExpression : ProjectionBindingExpression }) + { ValueBufferExpression: ProjectionBindingExpression }) { // ValueBufferExpression can be JsonQuery, ProjectionBindingExpression, EntityProjection // We only allow ProjectionBindingExpression which represents a regular entity @@ -1583,7 +1583,6 @@ private sealed class SharedTypeEntityExpandingExpressionVisitor : ExpressionVisi private readonly ISqlExpressionFactory _sqlExpressionFactory; private SelectExpression _selectExpression; - private DeferredOwnedExpansionRemovingVisitor _deferredOwnedExpansionRemover; public SharedTypeEntityExpandingExpressionVisitor( RelationalSqlTranslatingExpressionVisitor sqlTranslator, @@ -1592,15 +1591,13 @@ public SharedTypeEntityExpandingExpressionVisitor( _sqlTranslator = sqlTranslator; _sqlExpressionFactory = sqlExpressionFactory; _selectExpression = null!; - _deferredOwnedExpansionRemover = null!; } public Expression Expand(SelectExpression selectExpression, Expression lambdaBody) { _selectExpression = selectExpression; - _deferredOwnedExpansionRemover = new DeferredOwnedExpansionRemovingVisitor(_selectExpression); - return _deferredOwnedExpansionRemover.Visit(Visit(lambdaBody)); + return Visit(lambdaBody); } protected override Expression VisitMember(MemberExpression memberExpression) @@ -1634,12 +1631,6 @@ protected override Expression VisitExtension(Expression extensionExpression) private Expression? TryExpand(Expression? source, MemberIdentity member) { source = source.UnwrapTypeConversion(out var convertedType); - var doee = source as DeferredOwnedExpansionExpression; - if (doee is not null) - { - source = _deferredOwnedExpansionRemover.UnwrapDeferredEntityProjectionExpression(doee); - } - if (source is not EntityShaperExpression entityShaperExpression) { return null; @@ -1690,180 +1681,14 @@ protected override Expression VisitExtension(Expression extensionExpression) if (targetEntityType.IsMappedToJson()) { - var innerShaper = entityProjectionExpression.BindNavigation(navigation); - if (innerShaper != null) - { - return navigation.IsCollection - ? (JsonQueryExpression)innerShaper.ValueBufferExpression - : innerShaper; - } - } - else - { - if (navigation.IsCollection) - { - var innerSelectExpression = BuildInnerSelectExpressionForOwnedTypeMappedToDifferentTable( - entityProjectionExpression, - targetEntityType.GetViewOrTableMappings().Single().Table, - navigation); - - var innerShapedQuery = CreateShapedQueryExpression( - targetEntityType, innerSelectExpression); - - var makeNullable = foreignKey.PrincipalKey.Properties - .Concat(foreignKey.Properties) - .Select(p => p.ClrType) - .Any(t => t.IsNullableType()); - - var innerSequenceType = innerShapedQuery.Type.GetSequenceType(); - var correlationPredicateParameter = Expression.Parameter(innerSequenceType); - - var outerKey = entityShaperExpression.CreateKeyValuesExpression( - navigation.IsOnDependent - ? foreignKey.Properties - : foreignKey.PrincipalKey.Properties, - makeNullable); - var innerKey = correlationPredicateParameter.CreateKeyValuesExpression( - navigation.IsOnDependent - ? foreignKey.PrincipalKey.Properties - : foreignKey.Properties, - makeNullable); - - var keyComparison = Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKey, innerKey); - - var predicate = makeNullable - ? Expression.AndAlso( - outerKey is NewArrayExpression newArrayExpression - ? newArrayExpression.Expressions - .Select( - e => - { - var left = (e as UnaryExpression)?.Operand ?? e; - - return Expression.NotEqual(left, Expression.Constant(null, left.Type)); - }) - .Aggregate((l, r) => Expression.AndAlso(l, r)) - : Expression.NotEqual(outerKey, Expression.Constant(null, outerKey.Type)), - keyComparison) - : keyComparison; - - var correlationPredicate = Expression.Lambda(predicate, correlationPredicateParameter); - - return Expression.Call( - QueryableMethods.Where.MakeGenericMethod(innerSequenceType), - innerShapedQuery, - Expression.Quote(correlationPredicate)); - } - - var innerShaper = entityProjectionExpression.BindNavigation(navigation); - if (innerShaper == null) - { - // Owned types don't support inheritance See https://github.com/dotnet/efcore/issues/9630 - // So there is no handling for dependent having TPT/TPC - // If navigation is defined on derived type and entity type is part of TPT then we need to get ITableBase for derived type. - // TODO: The following code should also handle Function and SqlQuery mappings - var table = navigation.DeclaringEntityType.BaseType == null - || entityType.FindDiscriminatorProperty() != null - ? navigation.DeclaringEntityType.GetViewOrTableMappings().Single().Table - : navigation.DeclaringEntityType.GetViewOrTableMappings().Select(tm => tm.Table) - .Except(navigation.DeclaringEntityType.BaseType.GetViewOrTableMappings().Select(tm => tm.Table)) - .Single(); - if (table.GetReferencingRowInternalForeignKeys(foreignKey.PrincipalEntityType).Contains(foreignKey)) - { - // Mapped to same table - // We get identifying column to figure out tableExpression to pull columns from and nullability of most principal side - var identifyingColumn = entityProjectionExpression.BindProperty(entityType.FindPrimaryKey()!.Properties.First()); - var principalNullable = identifyingColumn.IsNullable - // Also make nullable if navigation is on derived type and and principal is TPT - // Since identifying PK would be non-nullable but principal can still be null - // Derived owned navigation does not de-dupe the PK column which for principal is from base table - // and for dependent on derived table - || (entityType.FindDiscriminatorProperty() == null - && navigation.DeclaringEntityType.IsStrictlyDerivedFrom(entityShaperExpression.EntityType)); - - var entityProjection = _selectExpression.GenerateWeakEntityProjectionExpression( - targetEntityType, table, identifyingColumn.Name, identifyingColumn.Table, principalNullable); - - if (entityProjection != null) - { - innerShaper = new RelationalEntityShaperExpression(targetEntityType, entityProjection, principalNullable); - } - } + var innerShaper = entityProjectionExpression.BindNavigation(navigation)!; - if (innerShaper == null) - { - // InnerShaper is still null if either it is not table sharing or we failed to find table to pick data from - // So we find the table it is mapped to and generate join with it. - // Owned types don't support inheritance See https://github.com/dotnet/efcore/issues/9630 - // So there is no handling for dependent having TPT - table = targetEntityType.GetViewOrTableMappings().Single().Table; - var innerSelectExpression = BuildInnerSelectExpressionForOwnedTypeMappedToDifferentTable( - entityProjectionExpression, - table, - navigation); - - var innerShapedQuery = CreateShapedQueryExpression(targetEntityType, innerSelectExpression); - - var makeNullable = foreignKey.PrincipalKey.Properties - .Concat(foreignKey.Properties) - .Select(p => p.ClrType) - .Any(t => t.IsNullableType()); - - var outerKey = entityShaperExpression.CreateKeyValuesExpression( - navigation.IsOnDependent - ? foreignKey.Properties - : foreignKey.PrincipalKey.Properties, - makeNullable); - var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValuesExpression( - navigation.IsOnDependent - ? foreignKey.PrincipalKey.Properties - : foreignKey.Properties, - makeNullable); - - var joinPredicate = _sqlTranslator.Translate( - Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKey, innerKey))!; - // Following conditions should match conditions for pushdown on outer during SelectExpression.AddJoin method - var pushdownRequired = _selectExpression.Limit != null - || _selectExpression.Offset != null - || _selectExpression.IsDistinct - || _selectExpression.GroupBy.Count > 0; - _selectExpression.AddLeftJoin(innerSelectExpression, joinPredicate); - - // If pushdown was required on SelectExpression then we need to fetch the updated entity projection - if (pushdownRequired) - { - if (doee is not null) - { - entityShaperExpression = _deferredOwnedExpansionRemover.UnwrapDeferredEntityProjectionExpression(doee); - } - - entityProjectionExpression = GetEntityProjectionExpression(entityShaperExpression); - } - - var leftJoinTable = _selectExpression.Tables.Last(); - - innerShaper = new RelationalEntityShaperExpression( - targetEntityType, - _selectExpression.GenerateWeakEntityProjectionExpression( - targetEntityType, table, null, leftJoinTable, nullable: true)!, - nullable: true); - } - - entityProjectionExpression.AddNavigationBinding(navigation, innerShaper); - } + return navigation.IsCollection + ? (JsonQueryExpression)innerShaper.ValueBufferExpression + : innerShaper; } - return doee is not null - ? doee.AddNavigation(targetEntityType, navigation) - : new DeferredOwnedExpansionExpression( - targetEntityType, - (ProjectionBindingExpression)entityShaperExpression.ValueBufferExpression, - navigation); - - SelectExpression BuildInnerSelectExpressionForOwnedTypeMappedToDifferentTable( - EntityProjectionExpression entityProjectionExpression, - ITableBase targetTable, - INavigation navigation) + if (navigation.IsCollection) { // just need any column - we use it only to extract the table it originated from var sourceColumn = entityProjectionExpression @@ -1873,16 +1698,61 @@ SelectExpression BuildInnerSelectExpressionForOwnedTypeMappedToDifferentTable( : foreignKey.PrincipalKey.Properties[0]); var sourceTable = FindRootTableExpressionForColumn(sourceColumn); - TableExpressionBase ownedTable = new TableExpression(targetTable); - - foreach (var annotation in sourceTable.GetAnnotations()) - { - ownedTable = ownedTable.AddAnnotation(annotation.Name, annotation.Value); - } - - return _sqlExpressionFactory.Select(targetEntityType, ownedTable); + var innerSelectExpression = _sqlExpressionFactory.Select(targetEntityType); + innerSelectExpression = (SelectExpression)new AnnotationApplyingExpressionVisitor(sourceTable.GetAnnotations().ToList()) + .Visit(innerSelectExpression); + + var innerShapedQuery = CreateShapedQueryExpression(targetEntityType, innerSelectExpression); + + var makeNullable = foreignKey.PrincipalKey.Properties + .Concat(foreignKey.Properties) + .Select(p => p.ClrType) + .Any(t => t.IsNullableType()); + + var innerSequenceType = innerShapedQuery.Type.GetSequenceType(); + var correlationPredicateParameter = Expression.Parameter(innerSequenceType); + + var outerKey = entityShaperExpression.CreateKeyValuesExpression( + navigation.IsOnDependent + ? foreignKey.Properties + : foreignKey.PrincipalKey.Properties, + makeNullable); + var innerKey = correlationPredicateParameter.CreateKeyValuesExpression( + navigation.IsOnDependent + ? foreignKey.PrincipalKey.Properties + : foreignKey.Properties, + makeNullable); + + var keyComparison = Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKey, innerKey); + + var predicate = makeNullable + ? Expression.AndAlso( + outerKey is NewArrayExpression newArrayExpression + ? newArrayExpression.Expressions + .Select( + e => + { + var left = (e as UnaryExpression)?.Operand ?? e; + + return Expression.NotEqual(left, Expression.Constant(null, left.Type)); + }) + .Aggregate((l, r) => Expression.AndAlso(l, r)) + : Expression.NotEqual(outerKey, Expression.Constant(null, outerKey.Type)), + keyComparison) + : keyComparison; + + var correlationPredicate = Expression.Lambda(predicate, correlationPredicateParameter); + + return Expression.Call( + QueryableMethods.Where.MakeGenericMethod(innerSequenceType), + innerShapedQuery, + Expression.Quote(correlationPredicate)); } + return entityProjectionExpression.BindNavigation(navigation) + ?? _selectExpression.GenerateOwnedReferenceEntityProjectionExpression( + entityProjectionExpression, navigation, _sqlExpressionFactory); + static TableExpressionBase FindRootTableExpressionForColumn(ColumnExpression column) { var table = column.Table; @@ -1907,6 +1777,33 @@ static TableExpressionBase FindRootTableExpressionForColumn(ColumnExpression col } } + private sealed class AnnotationApplyingExpressionVisitor : ExpressionVisitor + { + private readonly IReadOnlyList _annotations; + + public AnnotationApplyingExpressionVisitor(IReadOnlyList annotations) + { + _annotations = annotations; + } + + [return: NotNullIfNotNull("expression")] + public override Expression? Visit(Expression? expression) + { + if (expression is TableExpression te) + { + TableExpressionBase ownedTable = te; + foreach (var annotation in _annotations) + { + ownedTable = ownedTable.AddAnnotation(annotation.Name, annotation.Value); + } + + return ownedTable; + } + + return base.Visit(expression); + } + } + private bool TryGetJsonQueryExpression( EntityShaperExpression entityShaperExpression, [NotNullWhen(true)] out JsonQueryExpression? jsonQueryExpression) @@ -1935,86 +1832,6 @@ ProjectionBindingExpression projectionBindingExpression EntityProjectionExpression entityProjectionExpression => entityProjectionExpression, _ => throw new InvalidOperationException() }; - - private sealed class DeferredOwnedExpansionExpression : Expression - { - private readonly IEntityType _entityType; - - public DeferredOwnedExpansionExpression( - IEntityType entityType, - ProjectionBindingExpression projectionBindingExpression, - INavigation navigation) - { - _entityType = entityType; - ProjectionBindingExpression = projectionBindingExpression; - NavigationChain = new List { navigation }; - } - - private DeferredOwnedExpansionExpression( - IEntityType entityType, - ProjectionBindingExpression projectionBindingExpression, - List navigationChain) - { - _entityType = entityType; - ProjectionBindingExpression = projectionBindingExpression; - NavigationChain = navigationChain; - } - - public ProjectionBindingExpression ProjectionBindingExpression { get; } - public List NavigationChain { get; } - - public DeferredOwnedExpansionExpression AddNavigation(IEntityType entityType, INavigation navigation) - { - var navigationChain = new List(NavigationChain.Count + 1); - navigationChain.AddRange(NavigationChain); - navigationChain.Add(navigation); - - return new DeferredOwnedExpansionExpression( - entityType, - ProjectionBindingExpression, - navigationChain); - } - - public override Type Type - => _entityType.ClrType; - - public override ExpressionType NodeType - => ExpressionType.Extension; - } - - private sealed class DeferredOwnedExpansionRemovingVisitor : ExpressionVisitor - { - private readonly SelectExpression _selectExpression; - - public DeferredOwnedExpansionRemovingVisitor(SelectExpression selectExpression) - { - _selectExpression = selectExpression; - } - - [return: NotNullIfNotNull("expression")] - public override Expression? Visit(Expression? expression) - => expression switch - { - DeferredOwnedExpansionExpression doee => UnwrapDeferredEntityProjectionExpression(doee), - // For the source entity shaper or owned collection expansion - EntityShaperExpression or ShapedQueryExpression or GroupByShaperExpression or JsonQueryExpression => expression, - _ => base.Visit(expression) - }; - - public EntityShaperExpression UnwrapDeferredEntityProjectionExpression(DeferredOwnedExpansionExpression doee) - { - var entityProjection = (EntityProjectionExpression)_selectExpression.GetProjection(doee.ProjectionBindingExpression); - var entityShaper = entityProjection.BindNavigation(doee.NavigationChain[0])!; - - for (var i = 1; i < doee.NavigationChain.Count; i++) - { - entityProjection = (EntityProjectionExpression)entityShaper.ValueBufferExpression; - entityShaper = entityProjection.BindNavigation(doee.NavigationChain[i])!; - } - - return entityShaper; - } - } } private ShapedQueryExpression TranslateTwoParameterSelector(ShapedQueryExpression source, LambdaExpression resultSelector) diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 7141c689353..e66c357df5c 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.IO; using System.Runtime.CompilerServices; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.Query.Internal; @@ -210,7 +211,7 @@ internal SelectExpression(IEntityType entityType, ISqlExpressionFactory sqlExpre _projectionMapping[new ProjectionMember()] = entityProjection; } - break; + break; case RelationalAnnotationNames.TpcMappingStrategy: { @@ -344,7 +345,7 @@ internal SelectExpression(IEntityType entityType, ISqlExpressionFactory sqlExpre } } - break; + break; default: { @@ -424,7 +425,7 @@ internal SelectExpression(IEntityType entityType, ISqlExpressionFactory sqlExpre } } - break; + break; } void GenerateNonHierarchyNonSplittingEntityType(ITableBase table, TableExpressionBase tableExpression) @@ -1510,7 +1511,7 @@ Expression CopyProjectionToOuter(SelectExpression innerSelectExpression, Express return innerShaperExpression; } } - + else { var jsonProjectionDeduplicationMap = BuildJsonProjectionDeduplicationMap( _projectionMapping.Select(x => x.Value).OfType()); @@ -2520,114 +2521,272 @@ public void ApplyDefaultIfEmpty(ISqlExpressionFactory sqlExpressionFactory) /// doing so can result in application failures when updating to a new Entity Framework Core release. /// [EntityFrameworkInternal] - public EntityProjectionExpression? GenerateWeakEntityProjectionExpression( - IEntityType entityType, - ITableBase table, - string? columnName, - TableExpressionBase tableExpressionBase, - bool nullable = true) + public EntityShaperExpression GenerateOwnedReferenceEntityProjectionExpression( + EntityProjectionExpression principalEntityProjection, + INavigation navigation, + ISqlExpressionFactory sqlExpressionFactory) { - if (columnName == null) + // We first find the select expression where principal tableExpressionBase is located + // That is where we find shared tableExpressionBase to pull columns from or add joins + var identifyingColumn = principalEntityProjection.BindProperty( + navigation.DeclaringEntityType.FindPrimaryKey()!.Properties.First()); + + var expressions = GetPropertyExpressions(sqlExpressionFactory, navigation, this, identifyingColumn); + + var entityShaper = new RelationalEntityShaperExpression( + navigation.TargetEntityType, + new EntityProjectionExpression(navigation.TargetEntityType, expressions), + identifyingColumn.IsNullable || navigation.DeclaringEntityType.BaseType != null || !navigation.ForeignKey.IsRequiredDependent); + principalEntityProjection.AddNavigationBinding(navigation, entityShaper); + + return entityShaper; + + // Owned types don't support inheritance See https://github.com/dotnet/efcore/issues/9630 + // So there is no handling for dependent having hierarchy + // TODO: The following code should also handle Function and SqlQuery mappings when supported on owned type + static IReadOnlyDictionary GetPropertyExpressions( + ISqlExpressionFactory sqlExpressionFactory, + INavigation navigation, + SelectExpression selectExpression, + ColumnExpression identifyingColumn) { - // This is when projections are coming from a joined table. - var propertyExpressions = GetPropertyExpressionsFromJoinedTable( - entityType, table, FindTableReference(this, tableExpressionBase)); + var propertyExpressions = new Dictionary(); + var tableExpressionBase = UnwrapJoinExpression(identifyingColumn.Table); + if (tableExpressionBase is SelectExpression subquery) + { + // If identifying column is from a subquery then the owner table is inside subquery + // so we need to traverse in + var subqueryIdentifyingColumn = (ColumnExpression)subquery.Projection + .Single(e => string.Equals(e.Alias, identifyingColumn.Name, StringComparison.OrdinalIgnoreCase)) + .Expression; - return new EntityProjectionExpression(entityType, propertyExpressions); - } - else - { - var propertyExpressions = GetPropertyExpressionFromSameTable( - entityType, table, this, tableExpressionBase, columnName, nullable); + var subqueryPropertyExpressions = GetPropertyExpressions( + sqlExpressionFactory, navigation, subquery, subqueryIdentifyingColumn); + var changeNullability = identifyingColumn.IsNullable && !subqueryIdentifyingColumn.IsNullable; + var tableIndex = selectExpression._tables.FindIndex(e => ReferenceEquals(e, identifyingColumn.Table)); + var subqueryTableReferenceExpression = selectExpression._tableReferences[tableIndex]; + foreach (var (property, columnExpression) in subqueryPropertyExpressions) + { + var outerColumn = subquery.GenerateOuterColumn(subqueryTableReferenceExpression, columnExpression); + if (changeNullability) + { + outerColumn = outerColumn.MakeNullable(); + } + propertyExpressions[property] = outerColumn; + } - return propertyExpressions == null - ? null - : new EntityProjectionExpression(entityType, propertyExpressions); - } + return propertyExpressions; + } - static TableReferenceExpression FindTableReference(SelectExpression selectExpression, TableExpressionBase tableExpression) - { - var tableIndex = selectExpression._tables.FindIndex(e => ReferenceEquals(e, tableExpression)); - return selectExpression._tableReferences[tableIndex]; - } + // This is the select expression where owner table exists + // where we would look for same table or generate joins + var sourceTableForAnnotations = FindRootTableExpressionForColumn(identifyingColumn.Table, identifyingColumn.Name); + var ownerType = navigation.DeclaringEntityType; + var entityType = navigation.TargetEntityType; + var principalMappings = ownerType.GetViewOrTableMappings().Select(e => e.Table); + var derivedType = ownerType.BaseType != null; + var derivedTpt = derivedType && ownerType.GetMappingStrategy() == RelationalAnnotationNames.TptMappingStrategy; + var parentNullable = identifyingColumn.IsNullable; + var pkColumnsNullable = parentNullable + || (derivedType && ownerType.GetMappingStrategy() != RelationalAnnotationNames.TphMappingStrategy); + var newColumnsNullable = pkColumnsNullable || !navigation.ForeignKey.IsRequiredDependent; + if (derivedTpt) + { + principalMappings = principalMappings.Except(ownerType.BaseType!.GetViewOrTableMappings().Select(e => e.Table)); + } - static IReadOnlyDictionary? GetPropertyExpressionFromSameTable( - IEntityType entityType, - ITableBase table, - SelectExpression selectExpression, - TableExpressionBase tableExpressionBase, - string columnName, - bool nullable) - { - var unwrappedTable = UnwrapJoinExpression(tableExpressionBase); - if (unwrappedTable is TableExpression tableExpression) + var principalTables = principalMappings.ToList(); + var dependentTables = entityType.GetViewOrTableMappings().Select(e => e.Table).ToList(); + var baseTableIndex = selectExpression._tables.FindIndex(teb => ReferenceEquals(teb, identifyingColumn.Table)); + var dependentMainTable = dependentTables[0]; + var tableReferenceExpressionMap = new Dictionary(); + var keyProperties = entityType.FindPrimaryKey()!.Properties; + TableReferenceExpression mainTableReferenceExpression; + TableReferenceExpression tableReferenceExpression; + if (tableExpressionBase is TableExpression) { - if (!string.Equals(tableExpression.Name, table.Name, StringComparison.OrdinalIgnoreCase)) + // This has potential to pull data from existing table + // PrincipalTables count will be 1 except for entity splitting + var matchingTableIndex = principalTables.FindIndex(e => e == dependentMainTable); + // If dependent main table is not sharing then there is no table sharing at all in fragment + if (matchingTableIndex != -1) { - // Fetch the table for the type which is defining the navigation since dependent would be in that table - tableExpressionBase = selectExpression.Tables - .First( - e => + // Dependent is table sharing with principal in some form, we don't need to generate join to owner + // TableExpression from identifying column will point to base type for TPT + // This may not be table which originates Owned type + if (derivedTpt) + { + baseTableIndex = selectExpression._tables.FindIndex( + teb => ((TableExpression)UnwrapJoinExpression(teb)).Table == principalTables[0]); + } + var tableIndex = baseTableIndex + matchingTableIndex; + mainTableReferenceExpression = selectExpression._tableReferences[tableIndex]; + tableReferenceExpressionMap[dependentMainTable] = mainTableReferenceExpression; + if (dependentTables.Count > 1) + { + var joinColumns = new List(); + foreach (var property in keyProperties) + { + var columnExpression = new ConcreteColumnExpression( + property, dependentMainTable.FindColumn(property)!, mainTableReferenceExpression, + pkColumnsNullable); + propertyExpressions[property] = columnExpression; + joinColumns.Add(columnExpression); + } + + for (var i = 1; i < dependentTables.Count; i++) + { + var table = dependentTables[i]; + matchingTableIndex = principalTables.FindIndex(e => e == table); + if (matchingTableIndex != -1) { - var t = (TableExpression)UnwrapJoinExpression(e); - return t.Name == table.Name && t.Schema == table.Schema; - }); - } + // We don't need to generate join for this + tableReferenceExpressionMap[table] = selectExpression._tableReferences[baseTableIndex + matchingTableIndex]; + } + else + { + TableExpressionBase tableExpression = new TableExpression(table); + foreach (var annotation in sourceTableForAnnotations.GetAnnotations()) + { + tableExpression = tableExpression.AddAnnotation(annotation.Name, annotation.Value); + } + tableReferenceExpression = new TableReferenceExpression(selectExpression, tableExpression.Alias!); + tableReferenceExpressionMap[table] = tableReferenceExpression; - var propertyExpressions = new Dictionary(); - var tableReferenceExpression = FindTableReference(selectExpression, tableExpressionBase); - foreach (var property in entityType - .GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()) - .SelectMany(t => t.GetDeclaredProperties())) - { - propertyExpressions[property] = new ConcreteColumnExpression( - property, table.FindColumn(property)!, tableReferenceExpression, nullable || !property.IsPrimaryKey()); - } + var innerColumns = keyProperties.Select( + p => CreateColumnExpression(p, table, tableReferenceExpression, nullable: false)); + var joinPredicate = joinColumns.Zip(innerColumns, (l, r) => sqlExpressionFactory.Equal(l, r)) + .Aggregate((l, r) => sqlExpressionFactory.AndAlso(l, r)); - return propertyExpressions; + var joinExpression = new LeftJoinExpression(tableExpression, joinPredicate); + selectExpression._removableJoinTables.Add(selectExpression._tables.Count); + selectExpression.AddTable(joinExpression, tableReferenceExpression); + } + } + } + + foreach (var property in entityType.GetProperties()) + { + if (property.IsPrimaryKey() + && dependentTables.Count > 1) + { + continue; + } + + var columnBase = dependentTables.Count == 1 + ? dependentMainTable.FindColumn(property)! + : dependentTables.Select(e => e.FindColumn(property)).First(e => e != null)!; + propertyExpressions[property] = CreateColumnExpression( + property, columnBase, tableReferenceExpressionMap[columnBase.Table], + nullable: property.IsPrimaryKey() ? pkColumnsNullable : newColumnsNullable); + } + + return propertyExpressions; + } } - if (unwrappedTable is SelectExpression subquery) + // Either we encountered a custom table source or dependent is not sharing table + // In either case we need to generate join to owner + var ownerJoinColumns = new List(); + var ownerTableReferenceExpression = selectExpression._tableReferences[baseTableIndex]; + foreach (var property in navigation.ForeignKey.PrincipalKey.Properties) { - var subqueryIdentifyingColumn = (ColumnExpression)subquery.Projection - .Single(e => string.Equals(e.Alias, columnName, StringComparison.OrdinalIgnoreCase)) - .Expression; + var columnBase = principalTables.Select(e => e.FindColumn(property)).First(e => e != null)!; + var columnExpression = new ConcreteColumnExpression( + property, columnBase, ownerTableReferenceExpression, pkColumnsNullable); + ownerJoinColumns.Add(columnExpression); + } + TableExpressionBase ownedTable = new TableExpression(dependentMainTable); + foreach (var annotation in sourceTableForAnnotations.GetAnnotations()) + { + ownedTable = ownedTable.AddAnnotation(annotation.Name, annotation.Value); + } + mainTableReferenceExpression = new TableReferenceExpression(selectExpression, ownedTable.Alias!); + var outerJoinPredicate = ownerJoinColumns + .Zip(navigation.ForeignKey.Properties + .Select(p => CreateColumnExpression(p, dependentMainTable, mainTableReferenceExpression, nullable: false))) + .Select(i => sqlExpressionFactory.Equal(i.First, i.Second)) + .Aggregate((l, r) => sqlExpressionFactory.AndAlso(l, r)); + var joinedTable = new LeftJoinExpression(ownedTable, outerJoinPredicate); + tableReferenceExpressionMap[dependentMainTable] = mainTableReferenceExpression; + selectExpression.AddTable(joinedTable, mainTableReferenceExpression); + if (dependentTables.Count > 1) + { + var joinColumns = new List(); + foreach (var property in keyProperties) + { + var columnExpression = new ConcreteColumnExpression( + property, dependentMainTable.FindColumn(property)!, mainTableReferenceExpression, newColumnsNullable); + propertyExpressions[property] = columnExpression; + joinColumns.Add(columnExpression); + } - var subqueryPropertyExpressions = GetPropertyExpressionFromSameTable( - entityType, table, subquery, subqueryIdentifyingColumn.Table, subqueryIdentifyingColumn.Name, nullable); - if (subqueryPropertyExpressions == null) + for (var i = 1; i < dependentTables.Count; i++) { - return null; + var table = dependentTables[i]; + TableExpressionBase tableExpression = new TableExpression(table); + foreach (var annotation in sourceTableForAnnotations.GetAnnotations()) + { + tableExpression = tableExpression.AddAnnotation(annotation.Name, annotation.Value); + } + tableReferenceExpression = new TableReferenceExpression(selectExpression, tableExpression.Alias!); + tableReferenceExpressionMap[table] = tableReferenceExpression; + + var innerColumns = keyProperties.Select( + p => CreateColumnExpression(p, table, tableReferenceExpression, nullable: false)); + var joinPredicate = joinColumns.Zip(innerColumns, (l, r) => sqlExpressionFactory.Equal(l, r)) + .Aggregate((l, r) => sqlExpressionFactory.AndAlso(l, r)); + + var joinExpression = new LeftJoinExpression(tableExpression, joinPredicate); + selectExpression._removableJoinTables.Add(selectExpression._tables.Count); + selectExpression.AddTable(joinExpression, tableReferenceExpression); } + } - var newPropertyExpressions = new Dictionary(); - var tableReferenceExpression = FindTableReference(selectExpression, tableExpressionBase); - foreach (var (property, columnExpression) in subqueryPropertyExpressions) + foreach (var property in entityType.GetProperties()) + { + if (property.IsPrimaryKey() + && dependentTables.Count > 1) { - newPropertyExpressions[property] = subquery.GenerateOuterColumn(tableReferenceExpression, columnExpression); + continue; } - return newPropertyExpressions; + var columnBase = dependentTables.Count == 1 + ? dependentMainTable.FindColumn(property)! + : dependentTables.Select(e => e.FindColumn(property)).First(e => e != null)!; + propertyExpressions[property] = CreateColumnExpression( + property, columnBase, tableReferenceExpressionMap[columnBase.Table], + nullable: newColumnsNullable); + } + + foreach (var property in keyProperties) + { + selectExpression._identifier.Add((propertyExpressions[property], property.GetKeyValueComparer())); } - return null; + return propertyExpressions; } - static IReadOnlyDictionary GetPropertyExpressionsFromJoinedTable( - IEntityType entityType, - ITableBase table, - TableReferenceExpression tableReferenceExpression) + static TableExpressionBase FindRootTableExpressionForColumn(TableExpressionBase table, string columnName) { - var propertyExpressions = new Dictionary(); - foreach (var property in entityType - .GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive()) - .SelectMany(t => t.GetDeclaredProperties())) + if (table is JoinExpressionBase joinExpressionBase) + { + table = joinExpressionBase.Table; + } + else if (table is SetOperationBase setOperationBase) { - propertyExpressions[property] = new ConcreteColumnExpression( - property, table.FindColumn(property)!, tableReferenceExpression, nullable: true); + table = setOperationBase.Source1; } - return propertyExpressions; + if (table is SelectExpression selectExpression) + { + var matchingProjection = + (ColumnExpression)selectExpression.Projection.Where(p => p.Alias == columnName).Single().Expression; + + return FindRootTableExpressionForColumn(matchingProjection.Table, matchingProjection.Name); + } + + return table; } } diff --git a/test/EFCore.Relational.Specification.Tests/Query/EntitySplittingQueryFixtureBase.cs b/test/EFCore.Relational.Specification.Tests/Query/EntitySplittingQueryFixtureBase.cs deleted file mode 100644 index a4547c9a481..00000000000 --- a/test/EFCore.Relational.Specification.Tests/Query/EntitySplittingQueryFixtureBase.cs +++ /dev/null @@ -1,70 +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 Microsoft.EntityFrameworkCore.TestModels.EntitySplitting; - -namespace Microsoft.EntityFrameworkCore.Query; - -public abstract class EntitySplittingQueryFixtureBase : SharedStoreFixtureBase, IQueryFixtureBase -{ - protected override string StoreName - => "EntitySplittingQueryTest"; - - public TestSqlLoggerFactory TestSqlLoggerFactory - => (TestSqlLoggerFactory)ListLoggerFactory; - - public Func GetContextCreator() - => () => CreateContext(); - - public IReadOnlyDictionary EntityAsserters { get; } = new Dictionary> - { - { - typeof(SplitEntityOne), (e, a) => - { - Assert.Equal(e == null, a == null); - if (a != null) - { - var ee = (SplitEntityOne)e; - var aa = (SplitEntityOne)a; - - Assert.Equal(ee.Id, aa.Id); - Assert.Equal(ee.Value, aa.Value); - Assert.Equal(ee.SharedValue, aa.SharedValue); - Assert.Equal(ee.SplitValue, aa.SplitValue); - } - } - } - }.ToDictionary(e => e.Key, e => (object)e.Value); - - public IReadOnlyDictionary EntitySorters { get; } = - new Dictionary> { { typeof(SplitEntityOne), e => ((SplitEntityOne)e)?.Id }, }.ToDictionary( - e => e.Key, e => (object)e.Value); - - public ISetSource GetExpectedData() - => SplitEntityData.Instance; - - protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context) - { - modelBuilder.Entity( - b => - { - b.ToTable( - "SplitEntityOneMain", tb => - { - tb.Property(e => e.SharedValue); - }); - - b.SplitToTable( - "SplitEntityOneOther", tb => - { - tb.Property(e => e.SharedValue).HasColumnName("OtherSharedValue"); - tb.Property(e => e.SplitValue); - }); - }); - - base.OnModelCreating(modelBuilder, context); - } - - protected override void Seed(EntitySplittingContext context) - => SplitEntityData.Instance.Seed(context); -} diff --git a/test/EFCore.Relational.Specification.Tests/Query/EntitySplittingQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/EntitySplittingQueryTestBase.cs index fdbf38a829d..9fff6ca10b2 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/EntitySplittingQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/EntitySplittingQueryTestBase.cs @@ -1,35 +1,2922 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Globalization; using Microsoft.EntityFrameworkCore.TestModels.EntitySplitting; namespace Microsoft.EntityFrameworkCore.Query; -public abstract class EntitySplittingQueryTestBase : QueryTestBase - where TFixture : EntitySplittingQueryFixtureBase, new() +public abstract class EntitySplittingQueryTestBase : NonSharedModelTestBase { - public EntitySplittingQueryTestBase(TFixture fixture) - : base(fixture) + protected EntitySplittingQueryTestBase() { + _setSourceCreator = GetSetSourceCreator(); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual Task Can_query_entity_which_is_split(bool async) - => AssertQuery( + public virtual async Task Can_query_entity_which_is_split_in_two(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().SplitToTable("SplitEntityOnePart", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue3); + tb.Property(e => e.StringValue4); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + entryCount: 5); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Can_query_entity_which_is_split_in_three(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + entryCount: 5); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Can_query_entity_which_is_split_selecting_only_main_properties(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + + }); + + await AssertQuery( + async, + ss => ss.Set().Select(e => new { e.Id, e.IntValue1, e.StringValue1 }), + elementSorter: e => e.Id); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Can_query_entity_which_is_split_selecting_only_part_2_properties(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Select(e => new { e.Id, e.IntValue3, e.StringValue3 }), + elementSorter: e => e.Id); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Can_query_entity_which_is_split_selecting_only_part_3_properties(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Select(e => new { e.Id, e.IntValue4, e.StringValue4 }), + elementSorter: e => e.Id); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include_reference_to_split_entity(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Include(e => e.EntityOne), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.EntityOne)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include_collection_to_split_entity(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + mb.Entity().SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Include(e => e.EntityOnes), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.EntityOnes)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include_reference_to_split_entity_including_reference(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Include(e => e.EntityOne.EntityThree), + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(i => i.EntityOne), + new ExpectedInclude(i => i.EntityThree)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include_collection_to_split_entity_including_collection(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Include(e => e.EntityOnes).ThenInclude(e => e.EntityTwos), + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(i => i.EntityOnes), + new ExpectedInclude(i => i.EntityTwos)), + entryCount: 15); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include_reference_on_split_entity(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Include(e => e.EntityThree), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.EntityThree)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Include_collection_on_split_entity(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Include(e => e.EntityTwos), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.EntityTwos)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Custom_projection_trim_when_multiple_tables(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Select(e => new { e.IntValue1, e.IntValue3, e.EntityThree }), + elementSorter: e => e.IntValue1, + elementAsserter: (e, a) => + { + AssertEqual(e.IntValue1, a.IntValue1); + AssertEqual(e.IntValue3, a.IntValue3); + AssertEqual(e.EntityThree, a.EntityThree); + }, + entryCount: 3); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Normal_entity_owning_a_split_reference_with_main_fragment_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferenceExtras1", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferenceExtras2", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Normal_entity_owning_a_split_reference_with_main_fragment_sharing_custom_projection(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("EntityOnes"); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferenceExtras1", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferenceExtras2", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Select(e => new { e.Id, e.OwnedReference.OwnedIntValue4, e.OwnedReference.OwnedStringValue4 }), + elementSorter: e => e.Id, + elementAsserter: (e, a) => + { + AssertEqual(e.Id, a.Id); + AssertEqual(e.OwnedIntValue4, e.OwnedIntValue4); + AssertEqual(e.OwnedStringValue4, e.OwnedStringValue4); + }, + entryCount: 0); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("EntityOnes"); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferences"); + + o.SplitToTable("OwnedReferenceExtras1", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferenceExtras2", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing_custom_projection(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("EntityOnes"); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferences"); + + o.SplitToTable("OwnedReferenceExtras1", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferenceExtras2", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set().Select(e => new { e.Id, e.OwnedReference.OwnedIntValue4, e.OwnedReference.OwnedStringValue4 }), + elementSorter: e => e.Id, + elementAsserter: (e, a) => + { + AssertEqual(e.Id, a.Id); + AssertEqual(e.OwnedIntValue4, e.OwnedIntValue4); + AssertEqual(e.OwnedStringValue4, e.OwnedStringValue4); + }, + entryCount: 0); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Normal_entity_owning_a_split_collection(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("EntityOnes"); + + b.OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedCollection"); + + o.SplitToTable("OwnedCollectionExtras1", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedCollectionExtras2", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 15); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Normal_entity_owning_a_split_reference_with_main_fragment_sharing_multiple_level(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("EntityOnes"); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferenceExtras1", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferenceExtras2", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + + o.OwnsOne(e => e.OwnedNestedReference, + oo => + { + oo.SplitToTable("OwnedNestedReferenceExtras1", + t => + { + t.Property(e => e.OwnedNestedIntValue3); + t.Property(e => e.OwnedNestedStringValue3); + }); + + oo.SplitToTable("OwnedNestedReferenceExtras2", + t => + { + t.Property(e => e.OwnedNestedIntValue4); + t.Property(e => e.OwnedNestedStringValue4); + }); + + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(i => i.OwnedReference), + new ExpectedInclude(i => i.OwnedNestedReference)), + entryCount: 15); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_reference(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + + mb.Entity().OwnsOne(e => e.OwnedReference); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_collection(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + }); + + mb.Entity().OwnsMany(e => e.OwnedCollection); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 15); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_split_reference_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferences"); + + o.SplitToTable("OwnedReferenceExtras1", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferenceExtras2", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_split_collection(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + + b.OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedCollection"); + + o.SplitToTable("OwnedCollectionExtras1", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedCollectionExtras2", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 15); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_split_reference_with_table_sharing_1(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("SplitEntityOnePart1"); + + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("SplitEntityOnePart1"); + + o.SplitToTable("SplitEntityOnePart2", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("SplitEntityOnePart3", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory(Skip = "Issue#29104")] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_split_reference_with_table_sharing_2(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("SplitEntityOnePart1"); + + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("SplitEntityOnePart2"); + + o.SplitToTable("SplitEntityOnePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("SplitEntityOnePart1", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory(Skip = "Issue#29104")] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_split_reference_with_table_sharing_3(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("SplitEntityOnePart1"); + + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("SplitEntityOnePart3"); + + o.SplitToTable("SplitEntityOnePart2", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("SplitEntityOnePart1", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_split_reference_with_table_sharing_4(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("SplitEntityOnePart1"); + + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("SplitEntityOnePart1"); + + o.SplitToTable("SplitEntityOnePart2", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory(Skip = "Issue#29104")] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_split_reference_with_table_sharing_5(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("SplitEntityOnePart1"); + + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("SplitEntityOnePart2"); + + o.SplitToTable("SplitEntityOnePart1", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Split_entity_owning_a_split_reference_with_table_sharing_6(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity( + b => + { + b.ToTable("SplitEntityOnePart1"); + + b.SplitToTable("SplitEntityOnePart2", + tb => + { + tb.Property(e => e.IntValue3); + tb.Property(e => e.StringValue3); + }); + + b.SplitToTable("SplitEntityOnePart3", + tb => + { + tb.Property(e => e.IntValue4); + tb.Property(e => e.StringValue4); + }); + + b.OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("SplitEntityOnePart2"); + + o.SplitToTable("SplitEntityOnePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_reference_on_base_with_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_reference_on_base_with_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_reference_on_middle_with_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 6); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_reference_on_middle_with_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 6); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_reference_on_leaf_with_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 5); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_reference_on_leaf_with_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 5); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpc_entity_owning_a_split_reference_on_leaf_with_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTpcMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 5); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_reference_on_base_with_table_sharing_querying_sibling(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 2); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_reference_on_base_with_table_sharing_querying_sibling(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 2); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_reference_on_middle_with_table_sharing_querying_sibling(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a), + entryCount: 1); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_reference_on_middle_with_table_sharing_querying_sibling(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a), + entryCount: 1); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_reference_on_leaf_with_table_sharing_querying_sibling(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a), + entryCount: 1); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_reference_on_leaf_with_table_sharing_querying_sibling(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a), + entryCount: 1); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpc_entity_owning_a_split_reference_on_leaf_with_table_sharing_querying_sibling(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTpcMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a), + entryCount: 1); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_reference_on_base_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_reference_on_base_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpc_entity_owning_a_split_reference_on_base_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTpcMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_reference_on_middle_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 6); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_reference_on_middle_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 6); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpc_entity_owning_a_split_reference_on_middle_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTpcMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 6); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_reference_on_leaf_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 5); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_reference_on_leaf_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 5); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpc_entity_owning_a_split_reference_on_leaf_without_table_sharing(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTpcMappingStrategy(); + + mb.Entity() + .OwnsOne(e => e.OwnedReference, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedReference)), + entryCount: 5); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_collection_on_base(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_collection_on_base(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpc_entity_owning_a_split_collection_on_base(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTpcMappingStrategy(); + + mb.Entity() + .OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 10); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_collection_on_middle(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_collection_on_middle(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpc_entity_owning_a_split_collection_on_middle(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTpcMappingStrategy(); + + mb.Entity() + .OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 8); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tph_entity_owning_a_split_collection_on_leaf(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity() + .OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( + async, + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 7); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Tpt_entity_owning_a_split_collection_on_leaf(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTptMappingStrategy(); + + mb.Entity() + .OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( async, - ss => ss.Set()); + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 7); + } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] - public virtual Task Can_query_entity_which_is_split_selecting_only_main_properties(bool async) - => AssertQuery( + public virtual async Task Tpc_entity_owning_a_split_collection_on_leaf(bool async) + { + await InitializeContextFactoryAsync( + mb => + { + mb.Entity().UseTpcMappingStrategy(); + + mb.Entity() + .OwnsMany(e => e.OwnedCollection, + o => + { + o.ToTable("OwnedReferencePart1"); + + o.SplitToTable("OwnedReferencePart3", + t => + { + t.Property(e => e.OwnedIntValue3); + t.Property(e => e.OwnedStringValue3); + }); + + o.SplitToTable("OwnedReferencePart4", + t => + { + t.Property(e => e.OwnedIntValue4); + t.Property(e => e.OwnedStringValue4); + }); + }); + }); + + await AssertQuery( async, - ss => ss.Set().Select( - e => new + ss => ss.Set(), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(i => i.OwnedCollection)), + entryCount: 7); + } + + #region TestHelpers + + protected async Task AssertQuery( + bool async, + Func> queryCreator, + Func elementSorter = null, + Action elementAsserter = null, + bool assertOrder = false, + int entryCount = 0) + where TResult : class + { + using var context = CreateContext(); + var query = queryCreator(_setSourceCreator(context)); + + OrderingSettingsVerifier(assertOrder, query.Expression.Type, elementSorter); + + var actual = async + ? await query.ToListAsync() + : query.ToList(); + + var expectedData = GetExpectedData(); + var expected = queryCreator(expectedData).ToList(); + + if (!assertOrder + && elementSorter == null) + { + EntitySorters.TryGetValue(typeof(TResult), out var sorter); + elementSorter = (Func)sorter; + } + + if (elementAsserter == null) + { + EntityAsserters.TryGetValue(typeof(TResult), out var asserter); + elementAsserter = (Action)asserter; + } + + TestHelpers.AssertResults( + expected, + actual, + elementSorter, + elementAsserter, + assertOrder); + + Assert.Equal(entryCount, context.ChangeTracker.Entries().Count()); + } + + protected void AssertEqual(T expected, T actual, Action asserter = null) + { + if (asserter == null + && expected != null) + { + EntityAsserters.TryGetValue(typeof(T), out var entityAsserter); + asserter ??= (Action)entityAsserter; + } + + asserter ??= Assert.Equal; + asserter(expected, actual); + } + + protected void AssertCollection( + IEnumerable expected, + IEnumerable actual, + bool ordered = false, + Func elementSorter = null, + Action elementAsserter = null) + + { + if (expected == null + && actual == null) + { + return; + } + + if (expected == null != (actual == null)) + { + throw new InvalidOperationException( + $"Nullability doesn't match. Expected: {(expected == null ? "NULL" : "NOT NULL")}. Actual: {(actual == null ? "NULL." : "NOT NULL.")}."); + } + + EntitySorters.TryGetValue(typeof(TElement), out var sorter); + EntityAsserters.TryGetValue(typeof(TElement), out var asserter); + + elementSorter ??= (Func)sorter; + elementAsserter ??= (Action)asserter ?? Assert.Equal; + + if (!ordered) + { + if (elementSorter != null) + { + var sortedActual = actual.OrderBy(elementSorter).ToList(); + var sortedExpected = expected.OrderBy(elementSorter).ToList(); + + Assert.Equal(sortedExpected.Count, sortedActual.Count); + for (var i = 0; i < sortedExpected.Count; i++) + { + elementAsserter(sortedExpected[i], sortedActual[i]); + } + } + else + { + var sortedActual = actual.OrderBy(e => e).ToList(); + var sortedExpected = expected.OrderBy(e => e).ToList(); + + Assert.Equal(sortedExpected.Count, sortedActual.Count); + for (var i = 0; i < sortedExpected.Count; i++) + { + elementAsserter(sortedExpected[i], sortedActual[i]); + } + } + } + else + { + var expectedList = expected.ToList(); + var actualList = actual.ToList(); + + Assert.Equal(expectedList.Count, actualList.Count); + for (var i = 0; i < expectedList.Count; i++) + { + elementAsserter(expectedList[i], actualList[i]); + } + } + } + + private static readonly MethodInfo _assertIncludeEntity = + typeof(EntitySplittingQueryTestBase).GetTypeInfo().GetDeclaredMethod(nameof(AssertIncludeEntity)); + + private static readonly MethodInfo _assertIncludeCollectionMethodInfo = + typeof(EntitySplittingQueryTestBase).GetTypeInfo().GetDeclaredMethod(nameof(AssertIncludeCollection)); + + private static readonly MethodInfo _filteredIncludeMethodInfo = + typeof(EntitySplittingQueryTestBase).GetTypeInfo().GetDeclaredMethod(nameof(FilteredInclude)); + + private readonly List _includePath = new(); + + protected void AssertInclude( + TEntity expected, + TEntity actual, + params IExpectedInclude[] expectedIncludes) + => AssertIncludeInternal(expected, actual, expectedIncludes); + + private void AssertIncludeInternal(TEntity expected, TEntity actual, IExpectedInclude[] expectedIncludes) + { + _includePath.Clear(); + + AssertIncludeObject(expected, actual, expectedIncludes, assertOrder: false); + } + + private void AssertIncludeObject(object expected, object actual, IEnumerable expectedIncludes, bool assertOrder) + { + if (expected == null + && actual == null) + { + return; + } + + Assert.Equal(expected == null, actual == null); + + var expectedType = expected.GetType(); + if (expectedType.IsGenericType + && expectedType.GetTypeInfo().ImplementedInterfaces.Any( + i => i.IsConstructedGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable<>))) + { + _assertIncludeCollectionMethodInfo.MakeGenericMethod(expectedType.GenericTypeArguments[0]) + .Invoke(this, new[] { expected, actual, expectedIncludes, assertOrder }); + } + else + { + _assertIncludeEntity.MakeGenericMethod(expectedType).Invoke(this, new[] { expected, actual, expectedIncludes }); + } + } + + private void AssertIncludeEntity(TElement expected, TElement actual, IEnumerable expectedIncludes) + { + Assert.Equal(expected.GetType(), actual.GetType()); + + if (EntityAsserters.TryGetValue(typeof(TElement), out var asserter)) + { + ((Action)asserter)(expected, actual); + ProcessIncludes(expected, actual, expectedIncludes); + } + else + { + throw new InvalidOperationException($"Couldn't find entity asserter for entity type: '{typeof(TElement).Name}'."); + } + } + + private void AssertIncludeCollection( + IEnumerable expected, + IEnumerable actual, + IEnumerable expectedIncludes, + bool assertOrder) + { + var expectedList = expected.ToList(); + var actualList = actual.ToList(); + + if (!assertOrder && EntitySorters.TryGetValue(typeof(TElement), out var sorter)) + { + var actualSorter = (Func)sorter; + expectedList = expectedList.OrderBy(actualSorter).ToList(); + actualList = actualList.OrderBy(actualSorter).ToList(); + } + + Assert.Equal(expectedList.Count, actualList.Count); + + for (var i = 0; i < expectedList.Count; i++) + { + var elementType = expectedList[i].GetType(); + _assertIncludeEntity.MakeGenericMethod(elementType) + .Invoke(this, new object[] { expectedList[i], actualList[i], expectedIncludes }); + } + } + + private void ProcessIncludes(TEntity expected, TEntity actual, IEnumerable expectedIncludes) + { + var currentPath = string.Join(".", _includePath); + + foreach (var expectedInclude in expectedIncludes.OfType>().Where(i => i.NavigationPath == currentPath)) + { + var expectedIncludedNavigation = GetIncluded(expected, expectedInclude.IncludeMember); + var assertOrder = false; + if (expectedInclude.GetType().BaseType != typeof(object)) + { + var includedType = expectedInclude.GetType().GetGenericArguments()[1]; + var filterTypedMethod = _filteredIncludeMethodInfo.MakeGenericMethod(typeof(TEntity), includedType); + expectedIncludedNavigation = filterTypedMethod.Invoke( + this, + BindingFlags.NonPublic, + null, + new[] { expectedIncludedNavigation, expectedInclude }, + CultureInfo.CurrentCulture); + + assertOrder = (bool)expectedInclude.GetType() + .GetProperty(nameof(ExpectedFilteredInclude.AssertOrder)) + .GetValue(expectedInclude); + } + + var actualIncludedNavigation = GetIncluded(actual, expectedInclude.IncludeMember); + + _includePath.Add(expectedInclude.IncludeMember.Name); + + AssertIncludeObject(expectedIncludedNavigation, actualIncludedNavigation, expectedIncludes, assertOrder); + + _includePath.RemoveAt(_includePath.Count - 1); + } + } + + private IEnumerable FilteredInclude( + IEnumerable expected, + ExpectedFilteredInclude expectedFilteredInclude) + => expectedFilteredInclude.IncludeFilter(expected); + + private object GetIncluded(TEntity entity, MemberInfo includeMember) + => includeMember switch + { + FieldInfo fieldInfo => fieldInfo.GetValue(entity), + PropertyInfo propertyInfo => propertyInfo.GetValue(entity), + _ => throw new InvalidOperationException(), + }; + + protected void AssertGrouping( + IGrouping expected, + IGrouping actual, + bool ordered = false, + Func elementSorter = null, + Action keyAsserter = null, + Action elementAsserter = null) + { + keyAsserter ??= Assert.Equal; + keyAsserter(expected.Key, actual.Key); + AssertCollection(expected, actual, ordered, elementSorter, elementAsserter); + } + + private void OrderingSettingsVerifier(bool assertOrder, Type type, object elementSorter) + { + if (!assertOrder + && type.IsGenericType + && (type.GetGenericTypeDefinition() == typeof(IOrderedEnumerable<>) + || type.GetGenericTypeDefinition() == typeof(IOrderedQueryable<>))) + { + throw new InvalidOperationException( + "Query result is OrderedQueryable - you need to set AssertQuery option: 'assertOrder' to 'true'. If the resulting order is non-deterministic by design, add identity projection to the top of the query to disable this check."); + } + + if (assertOrder && elementSorter != null) + { + throw new InvalidOperationException("You shouldn't apply element sorter when 'assertOrder' is set to 'true'."); + } + } + + private readonly Func _setSourceCreator; + + private Func GetSetSourceCreator() + => context => new DefaultSetSource(context); + + protected void AssertSql(params string[] expected) + => TestSqlLoggerFactory.AssertBaseline(expected); + + // These are static so that they are shared across tests + private static IReadOnlyDictionary EntityAsserters { get; } + = new Dictionary> + { + { + typeof(EntityOne), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) + { + var ee = (EntityOne)e; + var aa = (EntityOne)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.IntValue1, aa.IntValue1); + Assert.Equal(ee.IntValue2, aa.IntValue2); + Assert.Equal(ee.IntValue3, aa.IntValue3); + Assert.Equal(ee.IntValue4, aa.IntValue4); + Assert.Equal(ee.StringValue1, aa.StringValue1); + Assert.Equal(ee.StringValue2, aa.StringValue2); + Assert.Equal(ee.StringValue3, aa.StringValue3); + Assert.Equal(ee.StringValue4, aa.StringValue4); + } + } + }, + { + typeof(EntityTwo), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) + { + var ee = (EntityTwo)e; + var aa = (EntityTwo)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.Name, aa.Name); + } + } + }, + { + typeof(EntityThree), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) + { + var ee = (EntityThree)e; + var aa = (EntityThree)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.Name, aa.Name); + } + } + }, + { + typeof(BaseEntity), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) + { + var ee = (BaseEntity)e; + var aa = (BaseEntity)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.BaseValue, aa.BaseValue); + if (ee is MiddleEntity me) + { + var ma = (MiddleEntity)aa; + Assert.Equal(me.MiddleValue, ma.MiddleValue); + + if (ee is LeafEntity le) + { + var la = (LeafEntity)aa; + Assert.Equal(le.LeafValue, la.LeafValue); + } + } + + if (ee is SiblingEntity se) + { + var sa = (SiblingEntity)aa; + Assert.Equal(se.SiblingValue, sa.SiblingValue); + } + } + } + }, + { + typeof(MiddleEntity), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) + { + var ee = (MiddleEntity)e; + var aa = (MiddleEntity)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.BaseValue, aa.BaseValue); + Assert.Equal(ee.MiddleValue, aa.MiddleValue); + + if (ee is LeafEntity le) + { + var la = (LeafEntity)aa; + Assert.Equal(le.LeafValue, la.LeafValue); + } + } + } + }, + { + typeof(SiblingEntity), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) + { + var ee = (SiblingEntity)e; + var aa = (SiblingEntity)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.BaseValue, aa.BaseValue); + Assert.Equal(ee.SiblingValue, aa.SiblingValue); + } + } + }, + { + typeof(LeafEntity), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) + { + var ee = (LeafEntity)e; + var aa = (LeafEntity)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.BaseValue, aa.BaseValue); + Assert.Equal(ee.MiddleValue, aa.MiddleValue); + Assert.Equal(ee.LeafValue, aa.LeafValue); + } + } + }, + { + typeof(OwnedReference), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) + { + var ee = (OwnedReference)e; + var aa = (OwnedReference)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.OwnedIntValue1, aa.OwnedIntValue1); + Assert.Equal(ee.OwnedIntValue2, aa.OwnedIntValue2); + Assert.Equal(ee.OwnedIntValue3, aa.OwnedIntValue3); + Assert.Equal(ee.OwnedIntValue4, aa.OwnedIntValue4); + Assert.Equal(ee.OwnedStringValue1, aa.OwnedStringValue1); + Assert.Equal(ee.OwnedStringValue2, aa.OwnedStringValue2); + Assert.Equal(ee.OwnedStringValue3, aa.OwnedStringValue3); + Assert.Equal(ee.OwnedStringValue4, aa.OwnedStringValue4); + } + } + }, + { + typeof(OwnedNestedReference), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) + { + var ee = (OwnedNestedReference)e; + var aa = (OwnedNestedReference)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.OwnedNestedIntValue1, aa.OwnedNestedIntValue1); + Assert.Equal(ee.OwnedNestedIntValue2, aa.OwnedNestedIntValue2); + Assert.Equal(ee.OwnedNestedIntValue3, aa.OwnedNestedIntValue3); + Assert.Equal(ee.OwnedNestedIntValue4, aa.OwnedNestedIntValue4); + Assert.Equal(ee.OwnedNestedStringValue1, aa.OwnedNestedStringValue1); + Assert.Equal(ee.OwnedNestedStringValue2, aa.OwnedNestedStringValue2); + Assert.Equal(ee.OwnedNestedStringValue3, aa.OwnedNestedStringValue3); + Assert.Equal(ee.OwnedNestedStringValue4, aa.OwnedNestedStringValue4); + } + } + }, + { + typeof(OwnedCollection), (e, a) => + { + Assert.Equal(e == null, a == null); + if (a != null) { - e.Id, - e.SharedValue, - e.Value - })); + var ee = (OwnedCollection)e; + var aa = (OwnedCollection)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.OwnedIntValue1, aa.OwnedIntValue1); + Assert.Equal(ee.OwnedIntValue2, aa.OwnedIntValue2); + Assert.Equal(ee.OwnedStringValue1, aa.OwnedStringValue1); + Assert.Equal(ee.OwnedStringValue2, aa.OwnedStringValue2); + } + } + }, + }.ToDictionary(e => e.Key, e => (object)e.Value); + + private static IReadOnlyDictionary EntitySorters { get; } + = new Dictionary> + { + { typeof(EntityOne), e => ((EntityOne)e)?.Id }, + { typeof(EntityTwo), e => ((EntityTwo)e)?.Id }, + { typeof(EntityThree), e => ((EntityThree)e)?.Id }, + { typeof(BaseEntity), e => ((BaseEntity)e)?.Id }, + { typeof(OwnedReference), e => ((OwnedReference)e)?.Id }, + { typeof(OwnedCollection), e => ((OwnedCollection)e)?.Id }, + { typeof(OwnedNestedReference), e => ((OwnedNestedReference)e)?.Id }, + }.ToDictionary(e => e.Key, e => (object)e.Value); + + protected virtual ISetSource GetExpectedData() + => EntitySplittingData.Instance; + + private class DefaultSetSource : ISetSource + { + private readonly DbContext _context; + + public DefaultSetSource(DbContext context) + { + _context = context; + } + + public IQueryable Set() + where TEntity : class + => _context.Set(); + } + + #endregion + + #region Fixture + + protected async Task InitializeContextFactoryAsync(Action onModelCreating) + => ContextFactory = await InitializeAsync( + mb => + { + OnModelCreating(mb); + onModelCreating(mb); + }, + onConfiguring: e => e.ConfigureWarnings(wc => + { + wc.Log(RelationalEventId.ForeignKeyTpcPrincipalWarning); + }), + shouldLogCategory: _ => true, seed: c => Seed(c)); + + protected virtual EntitySplittingContext CreateContext() + => ContextFactory.CreateContext(); + + public void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction) + => facade.UseTransaction(transaction.GetDbTransaction()); + + protected override string StoreName + => "EntitySplittingQueryTest"; + + protected TestSqlLoggerFactory TestSqlLoggerFactory + => (TestSqlLoggerFactory)ListLoggerFactory; + + protected ContextFactory ContextFactory { get; private set; } + + protected virtual void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().Property(e => e.Id).ValueGeneratedNever(); + modelBuilder.Entity().Property(e => e.Id).ValueGeneratedNever(); + modelBuilder.Entity().Property(e => e.Id).ValueGeneratedNever(); + modelBuilder.Entity().Property(e => e.Id).ValueGeneratedNever(); + modelBuilder.Entity(); + modelBuilder.Entity(); + modelBuilder.Entity(); + } + + protected virtual void Seed(EntitySplittingContext context) + => EntitySplittingData.Instance.Seed(context); + + public override void Dispose() + { + base.Dispose(); + + ContextFactory = null; + } + + #endregion } diff --git a/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingContext.cs b/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingContext.cs index 3c1201a306e..f074aedafee 100644 --- a/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingContext.cs +++ b/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingContext.cs @@ -9,6 +9,4 @@ public EntitySplittingContext(DbContextOptions options) : base(options) { } - - public DbSet SplitEntityOnes { get; set; } } diff --git a/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingData.cs b/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingData.cs new file mode 100644 index 00000000000..3beec43b17f --- /dev/null +++ b/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingData.cs @@ -0,0 +1,220 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.TestModels.EntitySplitting; + +public class EntitySplittingData : ISetSource +{ + public static readonly EntitySplittingData Instance = new(); + + private readonly EntityOne[] _entityOnes; + private readonly EntityTwo[] _entityTwos; + private readonly EntityThree[] _entityThrees; + private readonly BaseEntity[] _baseEntities; + + private EntitySplittingData() + { + _entityOnes = CreateEntityOnes(); + _entityTwos = CreateEntityTwos(); + _entityThrees = CreateEntityThrees(); + _baseEntities = CreateHierarchyEntities(); + + WireUp(); + } + + public IQueryable Set() + where TEntity : class + { + if (typeof(TEntity) == typeof(EntityOne)) + { + return (IQueryable)_entityOnes.AsQueryable(); + } + + if (typeof(TEntity) == typeof(EntityTwo)) + { + return (IQueryable)_entityTwos.AsQueryable(); + } + + if (typeof(TEntity) == typeof(EntityThree)) + { + return (IQueryable)_entityThrees.AsQueryable(); + } + + if (typeof(TEntity) == typeof(BaseEntity)) + { + return (IQueryable)_baseEntities.AsQueryable(); + } + + if (typeof(TEntity) == typeof(MiddleEntity)) + { + return (IQueryable)_baseEntities.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(SiblingEntity)) + { + return (IQueryable)_baseEntities.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(LeafEntity)) + { + return (IQueryable)_baseEntities.OfType().AsQueryable(); + } + + throw new InvalidOperationException("Invalid entity type: " + typeof(TEntity)); + } + + private static EntityOne[] CreateEntityOnes() + => new EntityOne[] + { + new EntityOne { Id = 1, IntValue1 = 11, IntValue2 = 12, IntValue3 = 13, IntValue4 = 14, + StringValue1 = "V11", StringValue2 = "V12", StringValue3 = "V13", StringValue4 = "V14"}, + new EntityOne { Id = 2, IntValue1 = 21, IntValue2 = 22, IntValue3 = 23, IntValue4 = 24, + StringValue1 = "V21", StringValue2 = "V22", StringValue3 = "V23", StringValue4 = "V24"}, + new EntityOne { Id = 3, IntValue1 = 31, IntValue2 = 32, IntValue3 = 33, IntValue4 = 34, + StringValue1 = "V31", StringValue2 = "V32", StringValue3 = "V33", StringValue4 = "V34"}, + new EntityOne { Id = 4, IntValue1 = 41, IntValue2 = 42, IntValue3 = 43, IntValue4 = 44, + StringValue1 = "V41", StringValue2 = "V42", StringValue3 = "V43", StringValue4 = "V44"}, + new EntityOne { Id = 5, IntValue1 = 51, IntValue2 = 52, IntValue3 = 53, IntValue4 = 54, + StringValue1 = "V51", StringValue2 = "V52", StringValue3 = "V53", StringValue4 = "V54"}, + }; + + private static EntityTwo[] CreateEntityTwos() + => new EntityTwo[] + { + new EntityTwo { Id = 1, Name = "Two1"}, + new EntityTwo { Id = 2, Name = "Two2"}, + new EntityTwo { Id = 3, Name = "Two3"}, + new EntityTwo { Id = 4, Name = "Two4"}, + new EntityTwo { Id = 5, Name = "Two5"}, + }; + + private static EntityThree[] CreateEntityThrees() + => new EntityThree[] + { + new EntityThree { Id = 1, Name = "Three1"}, + new EntityThree { Id = 2, Name = "Three2"}, + new EntityThree { Id = 3, Name = "Three3"}, + new EntityThree { Id = 4, Name = "Three4"}, + new EntityThree { Id = 5, Name = "Three5"}, + }; + + private static BaseEntity[] CreateHierarchyEntities() + => new BaseEntity[] + { + new BaseEntity { Id = 1, BaseValue = 1 }, + new MiddleEntity { Id = 2, BaseValue = 2, MiddleValue = 21 }, + new SiblingEntity { Id = 3, BaseValue = 3, SiblingValue = 21 }, + new LeafEntity { Id = 4, BaseValue = 4, MiddleValue = 22, LeafValue = 301 } + }; + + private void WireUp() + { + _entityTwos[0].EntityOne = _entityOnes[0]; + _entityTwos[1].EntityOne = _entityOnes[0]; + _entityTwos[2].EntityOne = _entityOnes[1]; + _entityTwos[3].EntityOne = _entityOnes[2]; + _entityTwos[4].EntityOne = _entityOnes[2]; + + _entityOnes[0].EntityThree = _entityThrees[0]; + _entityOnes[1].EntityThree = _entityThrees[0]; + _entityOnes[2].EntityThree = _entityThrees[1]; + _entityOnes[3].EntityThree = _entityThrees[2]; + _entityOnes[4].EntityThree = _entityThrees[2]; + + for (var i = 0; i < _entityOnes.Length; i++) + { + _entityOnes[i].OwnedReference = new OwnedReference + { + OwnedIntValue1 = i * 10 + 1, + OwnedIntValue2 = i * 10 + 2, + OwnedIntValue3 = i * 10 + 3, + OwnedIntValue4 = i * 10 + 4, + OwnedStringValue1 = "O" + i + "1", + OwnedStringValue2 = "O" + i + "2", + OwnedStringValue3 = "O" + i + "3", + OwnedStringValue4 = "O" + i + "4", + OwnedNestedReference = new OwnedNestedReference + { + OwnedNestedIntValue1 = i * 100 + 1, + OwnedNestedIntValue2 = i * 100 + 2, + OwnedNestedIntValue3 = i * 100 + 3, + OwnedNestedIntValue4 = i * 100 + 4, + OwnedNestedStringValue1 = "ON" + i + "1", + OwnedNestedStringValue2 = "ON" + i + "2", + OwnedNestedStringValue3 = "ON" + i + "3", + OwnedNestedStringValue4 = "ON" + i + "4" + } + }; + + for (var j = 0; j < i; j++) + { + _entityOnes[i].OwnedCollection.Add(new OwnedCollection + { + Id = i * 100 + j, + OwnedIntValue1 = i * 10 + 1, + OwnedIntValue2 = i * 10 + 2, + OwnedIntValue3 = i * 10 + 3, + OwnedIntValue4 = i * 10 + 4, + OwnedStringValue1 = "O" + i + "1", + OwnedStringValue2 = "O" + i + "2", + OwnedStringValue3 = "O" + i + "3", + OwnedStringValue4 = "O" + i + "4" + }); + } + } + + for (var i = 0; i < _baseEntities.Length; i++) + { + _baseEntities[i].OwnedReference = new OwnedReference + { + OwnedIntValue1 = i * 10 + 1, + OwnedIntValue2 = i * 10 + 2, + OwnedIntValue3 = i * 10 + 3, + OwnedIntValue4 = i * 10 + 4, + OwnedStringValue1 = "O" + i + "1", + OwnedStringValue2 = "O" + i + "2", + OwnedStringValue3 = "O" + i + "3", + OwnedStringValue4 = "O" + i + "4", + OwnedNestedReference = new OwnedNestedReference + { + OwnedNestedIntValue1 = i * 100 + 1, + OwnedNestedIntValue2 = i * 100 + 2, + OwnedNestedIntValue3 = i * 100 + 3, + OwnedNestedIntValue4 = i * 100 + 4, + OwnedNestedStringValue1 = "ON" + i + "1", + OwnedNestedStringValue2 = "ON" + i + "2", + OwnedNestedStringValue3 = "ON" + i + "3", + OwnedNestedStringValue4 = "ON" + i + "4" + } + }; + + for (var j = 0; j < i; j++) + { + _baseEntities[i].OwnedCollection.Add(new OwnedCollection + { + Id = i * 100 + j, + OwnedIntValue1 = i * 10 + 1, + OwnedIntValue2 = i * 10 + 2, + OwnedIntValue3 = i * 10 + 3, + OwnedIntValue4 = i * 10 + 4, + OwnedStringValue1 = "O" + i + "1", + OwnedStringValue2 = "O" + i + "2", + OwnedStringValue3 = "O" + i + "3", + OwnedStringValue4 = "O" + i + "4" + }); + } + } + } + + public void Seed(EntitySplittingContext context) + { + // Seed data cannot contain any store generated value, + // or recreate instances when calling AddRange + context.AddRange(_entityOnes); + context.AddRange(_entityTwos); + context.AddRange(_entityThrees); + context.AddRange(_baseEntities); + + context.SaveChanges(); + } +} diff --git a/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingTypes.cs b/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingTypes.cs new file mode 100644 index 00000000000..a461de04b59 --- /dev/null +++ b/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/EntitySplittingTypes.cs @@ -0,0 +1,110 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel.DataAnnotations.Schema; + +namespace Microsoft.EntityFrameworkCore.TestModels.EntitySplitting; + +public class EntityOne +{ + public int Id { get; set; } + public string StringValue1 { get; set; } + public string StringValue2 { get; set; } + public string StringValue3 { get; set; } + public string StringValue4 { get; set; } + public int IntValue1 { get; set; } + public int IntValue2 { get; set; } + public int IntValue3 { get; set; } + public int IntValue4 { get; set; } + public List EntityTwos { get; set; } = new(); + public EntityThree EntityThree { get; set; } + + [NotMapped] + public OwnedReference OwnedReference { get; set; } + [NotMapped] + public List OwnedCollection { get; set; } = new(); +} + +public class EntityTwo +{ + public int Id { get; set; } + public string Name { get; set; } + public EntityOne EntityOne { get; set; } +} + +public class EntityThree +{ + public int Id { get; set; } + public string Name { get; set; } + public List EntityOnes { get; set; } = new(); +} + +public class OwnedReference +{ + public int Id { get; set; } + public string OwnedStringValue1 { get; set; } + public string OwnedStringValue2 { get; set; } + public string OwnedStringValue3 { get; set; } + public string OwnedStringValue4 { get; set; } + public int OwnedIntValue1 { get; set; } + public int OwnedIntValue2 { get; set; } + public int OwnedIntValue3 { get; set; } + public int OwnedIntValue4 { get; set; } + + [NotMapped] + public OwnedNestedReference OwnedNestedReference { get; set; } +} + + +public class OwnedCollection +{ + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int Id { get; set; } + public string OwnedStringValue1 { get; set; } + public string OwnedStringValue2 { get; set; } + public string OwnedStringValue3 { get; set; } + public string OwnedStringValue4 { get; set; } + public int OwnedIntValue1 { get; set; } + public int OwnedIntValue2 { get; set; } + public int OwnedIntValue3 { get; set; } + public int OwnedIntValue4 { get; set; } +} + +public class OwnedNestedReference +{ + public int Id { get; set; } + public string OwnedNestedStringValue1 { get; set; } + public string OwnedNestedStringValue2 { get; set; } + public string OwnedNestedStringValue3 { get; set; } + public string OwnedNestedStringValue4 { get; set; } + public int OwnedNestedIntValue1 { get; set; } + public int OwnedNestedIntValue2 { get; set; } + public int OwnedNestedIntValue3 { get; set; } + public int OwnedNestedIntValue4 { get; set; } +} + +public class BaseEntity +{ + public int Id { get; set; } + public int BaseValue { get; set; } + + [NotMapped] + public OwnedReference OwnedReference { get; set; } + [NotMapped] + public List OwnedCollection { get; set; } = new(); +} + +public class MiddleEntity : BaseEntity +{ + public int MiddleValue { get; set; } +} + +public class SiblingEntity : BaseEntity +{ + public int SiblingValue { get; set; } +} + +public class LeafEntity : MiddleEntity +{ + public int LeafValue { get; set; } +} diff --git a/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/SplitEntityData.cs b/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/SplitEntityData.cs deleted file mode 100644 index cd5eb38948d..00000000000 --- a/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/SplitEntityData.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.EntityFrameworkCore.TestModels.EntitySplitting; - -public class SplitEntityData : ISetSource -{ - public static readonly SplitEntityData Instance = new(); - - private readonly SplitEntityOne[] _splitEntityOnes; - - private SplitEntityData() - { - _splitEntityOnes = CreateSplitEntityOnes(); - } - - public IQueryable Set() - where TEntity : class - { - if (typeof(TEntity) == typeof(SplitEntityOne)) - { - return (IQueryable)_splitEntityOnes.AsQueryable(); - } - - throw new InvalidOperationException("Invalid entity type: " + typeof(TEntity)); - } - - private static SplitEntityOne[] CreateSplitEntityOnes() - => new SplitEntityOne[] { }; - - public void Seed(EntitySplittingContext context) - { - context.AddRange(_splitEntityOnes); - - context.SaveChanges(); - } -} diff --git a/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/SplitEntityOne.cs b/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/SplitEntityOne.cs deleted file mode 100644 index d067f94623a..00000000000 --- a/test/EFCore.Relational.Specification.Tests/TestModels/EntitySplitting/SplitEntityOne.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.EntityFrameworkCore.TestModels.EntitySplitting; - -public class SplitEntityOne -{ - public int Id { get; set; } - public string Value { get; set; } - public int SharedValue { get; set; } - public string SplitValue { get; set; } -} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/EntitySplittingQuerySqlServerFixture.cs b/test/EFCore.SqlServer.FunctionalTests/Query/EntitySplittingQuerySqlServerFixture.cs deleted file mode 100644 index f935b669f31..00000000000 --- a/test/EFCore.SqlServer.FunctionalTests/Query/EntitySplittingQuerySqlServerFixture.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.EntityFrameworkCore.Query; - -public class EntitySplittingQuerySqlServerFixture : EntitySplittingQueryFixtureBase -{ - protected override ITestStoreFactory TestStoreFactory - => SqlServerTestStoreFactory.Instance; -} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/EntitySplittingQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/EntitySplittingQuerySqlServerTest.cs index c2399a9e26b..f015477fdd7 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/EntitySplittingQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/EntitySplittingQuerySqlServerTest.cs @@ -3,27 +3,26 @@ namespace Microsoft.EntityFrameworkCore.Query; -public class EntitySplittingQuerySqlServerTest : EntitySplittingQueryTestBase +public class EntitySplittingQuerySqlServerTest : EntitySplittingQueryTestBase { - public EntitySplittingQuerySqlServerTest(EntitySplittingQuerySqlServerFixture fixture, ITestOutputHelper testOutputHelper) - : base(fixture) + protected override ITestStoreFactory TestStoreFactory => SqlServerTestStoreFactory.Instance; + + public EntitySplittingQuerySqlServerTest() { - Fixture.TestSqlLoggerFactory.Clear(); - //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } [ConditionalFact] public virtual void Check_all_tests_overridden() => TestHelpers.AssertAllMethodsOverridden(GetType()); - public override async Task Can_query_entity_which_is_split(bool async) + public override async Task Can_query_entity_which_is_split_in_two(bool async) { - await base.Can_query_entity_which_is_split(async); + await base.Can_query_entity_which_is_split_in_two(async); AssertSql( - @"SELECT [s].[Id], [s].[SharedValue], [s0].[SplitValue], [s].[Value] -FROM [SplitEntityOneMain] AS [s] -INNER JOIN [SplitEntityOneOther] AS [s0] ON [s].[Id] = [s0].[Id]"); + @"SELECT [e].[Id], [e].[EntityThreeId], [e].[IntValue1], [e].[IntValue2], [s].[IntValue3], [s].[IntValue4], [e].[StringValue1], [e].[StringValue2], [s].[StringValue3], [s].[StringValue4] +FROM [EntityOne] AS [e] +INNER JOIN [SplitEntityOnePart] AS [s] ON [e].[Id] = [s].[Id]"); } public override async Task Can_query_entity_which_is_split_selecting_only_main_properties(bool async) @@ -31,10 +30,692 @@ public override async Task Can_query_entity_which_is_split_selecting_only_main_p await base.Can_query_entity_which_is_split_selecting_only_main_properties(async); AssertSql( - @"SELECT [s].[Id], [s].[SharedValue], [s].[Value] -FROM [SplitEntityOneMain] AS [s]"); + @"SELECT [e].[Id], [e].[IntValue1], [e].[StringValue1] +FROM [EntityOne] AS [e]"); + } + + public override async Task Can_query_entity_which_is_split_in_three(bool async) + { + await base.Can_query_entity_which_is_split_in_three(async); + + AssertSql( + @"SELECT [e].[Id], [e].[EntityThreeId], [e].[IntValue1], [e].[IntValue2], [s0].[IntValue3], [s].[IntValue4], [e].[StringValue1], [e].[StringValue2], [s0].[StringValue3], [s].[StringValue4] +FROM [EntityOne] AS [e] +INNER JOIN [SplitEntityOnePart3] AS [s] ON [e].[Id] = [s].[Id] +INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e].[Id] = [s0].[Id]"); + } + + public override async Task Can_query_entity_which_is_split_selecting_only_part_2_properties(bool async) + { + await base.Can_query_entity_which_is_split_selecting_only_part_2_properties(async); + + AssertSql( + @"SELECT [e].[Id], [s0].[IntValue3], [s0].[StringValue3] +FROM [EntityOne] AS [e] +INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e].[Id] = [s0].[Id]"); + } + + public override async Task Can_query_entity_which_is_split_selecting_only_part_3_properties(bool async) + { + await base.Can_query_entity_which_is_split_selecting_only_part_3_properties(async); + + AssertSql( + @"SELECT [e].[Id], [s].[IntValue4], [s].[StringValue4] +FROM [EntityOne] AS [e] +INNER JOIN [SplitEntityOnePart3] AS [s] ON [e].[Id] = [s].[Id]"); + } + + public override async Task Include_reference_to_split_entity(bool async) + { + await base.Include_reference_to_split_entity(async); + + AssertSql( + @"SELECT [e].[Id], [e].[EntityOneId], [e].[Name], [t].[Id], [t].[EntityThreeId], [t].[IntValue1], [t].[IntValue2], [t].[IntValue3], [t].[IntValue4], [t].[StringValue1], [t].[StringValue2], [t].[StringValue3], [t].[StringValue4] +FROM [EntityTwo] AS [e] +LEFT JOIN ( + SELECT [e0].[Id], [e0].[EntityThreeId], [e0].[IntValue1], [e0].[IntValue2], [s0].[IntValue3], [s].[IntValue4], [e0].[StringValue1], [e0].[StringValue2], [s0].[StringValue3], [s].[StringValue4] + FROM [EntityOne] AS [e0] + INNER JOIN [SplitEntityOnePart3] AS [s] ON [e0].[Id] = [s].[Id] + INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e0].[Id] = [s0].[Id] +) AS [t] ON [e].[EntityOneId] = [t].[Id]"); + } + + public override async Task Include_collection_to_split_entity(bool async) + { + await base.Include_collection_to_split_entity(async); + + AssertSql( + @"SELECT [e].[Id], [e].[Name], [t].[Id], [t].[EntityThreeId], [t].[IntValue1], [t].[IntValue2], [t].[IntValue3], [t].[IntValue4], [t].[StringValue1], [t].[StringValue2], [t].[StringValue3], [t].[StringValue4] +FROM [EntityThree] AS [e] +LEFT JOIN ( + SELECT [e0].[Id], [e0].[EntityThreeId], [e0].[IntValue1], [e0].[IntValue2], [s0].[IntValue3], [s].[IntValue4], [e0].[StringValue1], [e0].[StringValue2], [s0].[StringValue3], [s].[StringValue4] + FROM [EntityOne] AS [e0] + INNER JOIN [SplitEntityOnePart3] AS [s] ON [e0].[Id] = [s].[Id] + INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e0].[Id] = [s0].[Id] +) AS [t] ON [e].[Id] = [t].[EntityThreeId] +ORDER BY [e].[Id]"); + } + + public override async Task Include_reference_to_split_entity_including_reference(bool async) + { + await base.Include_reference_to_split_entity_including_reference(async); + + AssertSql( + @"SELECT [e].[Id], [e].[EntityOneId], [e].[Name], [t].[Id], [t].[EntityThreeId], [t].[IntValue1], [t].[IntValue2], [t].[IntValue3], [t].[IntValue4], [t].[StringValue1], [t].[StringValue2], [t].[StringValue3], [t].[StringValue4], [e1].[Id], [e1].[Name] +FROM [EntityTwo] AS [e] +LEFT JOIN ( + SELECT [e0].[Id], [e0].[EntityThreeId], [e0].[IntValue1], [e0].[IntValue2], [s0].[IntValue3], [s].[IntValue4], [e0].[StringValue1], [e0].[StringValue2], [s0].[StringValue3], [s].[StringValue4] + FROM [EntityOne] AS [e0] + INNER JOIN [SplitEntityOnePart3] AS [s] ON [e0].[Id] = [s].[Id] + INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e0].[Id] = [s0].[Id] +) AS [t] ON [e].[EntityOneId] = [t].[Id] +LEFT JOIN [EntityThree] AS [e1] ON [t].[EntityThreeId] = [e1].[Id]"); + } + + public override async Task Include_collection_to_split_entity_including_collection(bool async) + { + await base.Include_collection_to_split_entity_including_collection(async); + + AssertSql( + @"SELECT [e].[Id], [e].[Name], [t].[Id], [t].[EntityThreeId], [t].[IntValue1], [t].[IntValue2], [t].[IntValue3], [t].[IntValue4], [t].[StringValue1], [t].[StringValue2], [t].[StringValue3], [t].[StringValue4], [t].[Id0], [t].[EntityOneId], [t].[Name] +FROM [EntityThree] AS [e] +LEFT JOIN ( + SELECT [e0].[Id], [e0].[EntityThreeId], [e0].[IntValue1], [e0].[IntValue2], [s0].[IntValue3], [s].[IntValue4], [e0].[StringValue1], [e0].[StringValue2], [s0].[StringValue3], [s].[StringValue4], [e1].[Id] AS [Id0], [e1].[EntityOneId], [e1].[Name] + FROM [EntityOne] AS [e0] + INNER JOIN [SplitEntityOnePart3] AS [s] ON [e0].[Id] = [s].[Id] + INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e0].[Id] = [s0].[Id] + LEFT JOIN [EntityTwo] AS [e1] ON [e0].[Id] = [e1].[EntityOneId] +) AS [t] ON [e].[Id] = [t].[EntityThreeId] +ORDER BY [e].[Id], [t].[Id]"); + } + + public override async Task Include_reference_on_split_entity(bool async) + { + await base.Include_reference_on_split_entity(async); + + AssertSql( + @"SELECT [e].[Id], [e].[EntityThreeId], [e].[IntValue1], [e].[IntValue2], [s0].[IntValue3], [s].[IntValue4], [e].[StringValue1], [e].[StringValue2], [s0].[StringValue3], [s].[StringValue4], [e0].[Id], [e0].[Name] +FROM [EntityOne] AS [e] +INNER JOIN [SplitEntityOnePart3] AS [s] ON [e].[Id] = [s].[Id] +INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e].[Id] = [s0].[Id] +LEFT JOIN [EntityThree] AS [e0] ON [e].[EntityThreeId] = [e0].[Id]"); + } + + public override async Task Include_collection_on_split_entity(bool async) + { + await base.Include_collection_on_split_entity(async); + + AssertSql( + @"SELECT [e].[Id], [e].[EntityThreeId], [e].[IntValue1], [e].[IntValue2], [s0].[IntValue3], [s].[IntValue4], [e].[StringValue1], [e].[StringValue2], [s0].[StringValue3], [s].[StringValue4], [e0].[Id], [e0].[EntityOneId], [e0].[Name] +FROM [EntityOne] AS [e] +INNER JOIN [SplitEntityOnePart3] AS [s] ON [e].[Id] = [s].[Id] +INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e].[Id] = [s0].[Id] +LEFT JOIN [EntityTwo] AS [e0] ON [e].[Id] = [e0].[EntityOneId] +ORDER BY [e].[Id]"); + } + + public override async Task Custom_projection_trim_when_multiple_tables(bool async) + { + await base.Custom_projection_trim_when_multiple_tables(async); + + AssertSql( + @"SELECT [e].[IntValue1], [s0].[IntValue3], [e0].[Id], [e0].[Name] +FROM [EntityOne] AS [e] +INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e].[Id] = [s0].[Id] +LEFT JOIN [EntityThree] AS [e0] ON [e].[EntityThreeId] = [e0].[Id]"); + } + + public override async Task Normal_entity_owning_a_split_reference_with_main_fragment_sharing(bool async) + { + await base.Normal_entity_owning_a_split_reference_with_main_fragment_sharing(async); + + AssertSql( + @"SELECT [e].[Id], [e].[EntityThreeId], [e].[IntValue1], [e].[IntValue2], [e].[IntValue3], [e].[IntValue4], [e].[StringValue1], [e].[StringValue2], [e].[StringValue3], [e].[StringValue4], [e].[OwnedReference_Id], [e].[OwnedReference_OwnedIntValue1], [e].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [e].[OwnedReference_OwnedStringValue1], [e].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [EntityOne] AS [e] +LEFT JOIN [OwnedReferenceExtras2] AS [o] ON [e].[Id] = [o].[EntityOneId] +LEFT JOIN [OwnedReferenceExtras1] AS [o0] ON [e].[Id] = [o0].[EntityOneId]"); + } + + public override async Task Normal_entity_owning_a_split_reference_with_main_fragment_sharing_custom_projection(bool async) + { + await base.Normal_entity_owning_a_split_reference_with_main_fragment_sharing_custom_projection(async); + + AssertSql( + @"SELECT [e].[Id], CASE + WHEN [e].[OwnedReference_Id] IS NOT NULL AND [e].[OwnedReference_OwnedIntValue1] IS NOT NULL AND [e].[OwnedReference_OwnedIntValue2] IS NOT NULL THEN [o].[OwnedIntValue4] +END AS [OwnedIntValue4], CASE + WHEN [e].[OwnedReference_Id] IS NOT NULL AND [e].[OwnedReference_OwnedIntValue1] IS NOT NULL AND [e].[OwnedReference_OwnedIntValue2] IS NOT NULL THEN [o].[OwnedStringValue4] +END AS [OwnedStringValue4] +FROM [EntityOnes] AS [e] +LEFT JOIN [OwnedReferenceExtras2] AS [o] ON [e].[Id] = [o].[EntityOneId]"); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing(bool async) + { + await base.Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing_custom_projection(bool async) + { + await base.Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing_custom_projection(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Normal_entity_owning_a_split_collection(bool async) + { + await base.Normal_entity_owning_a_split_collection(async); + + AssertSql(); + } + + public override async Task Normal_entity_owning_a_split_reference_with_main_fragment_sharing_multiple_level(bool async) + { + await base.Normal_entity_owning_a_split_reference_with_main_fragment_sharing_multiple_level(async); + + AssertSql( + @"SELECT [e].[Id], [e].[EntityThreeId], [e].[IntValue1], [e].[IntValue2], [e].[IntValue3], [e].[IntValue4], [e].[StringValue1], [e].[StringValue2], [e].[StringValue3], [e].[StringValue4], [e].[OwnedReference_Id], [e].[OwnedReference_OwnedIntValue1], [e].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [e].[OwnedReference_OwnedStringValue1], [e].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4], [e].[OwnedReference_OwnedNestedReference_Id], [e].[OwnedReference_OwnedNestedReference_OwnedNestedIntValue1], [e].[OwnedReference_OwnedNestedReference_OwnedNestedIntValue2], [o2].[OwnedNestedIntValue3], [o1].[OwnedNestedIntValue4], [e].[OwnedReference_OwnedNestedReference_OwnedNestedStringValue1], [e].[OwnedReference_OwnedNestedReference_OwnedNestedStringValue2], [o2].[OwnedNestedStringValue3], [o1].[OwnedNestedStringValue4] +FROM [EntityOnes] AS [e] +LEFT JOIN [OwnedReferenceExtras2] AS [o] ON [e].[Id] = [o].[EntityOneId] +LEFT JOIN [OwnedReferenceExtras1] AS [o0] ON [e].[Id] = [o0].[EntityOneId] +LEFT JOIN [OwnedNestedReferenceExtras2] AS [o1] ON [e].[Id] = [o1].[OwnedReferenceEntityOneId] +LEFT JOIN [OwnedNestedReferenceExtras1] AS [o2] ON [e].[Id] = [o2].[OwnedReferenceEntityOneId]"); + } + + public override async Task Split_entity_owning_a_reference(bool async) + { + await base.Split_entity_owning_a_reference(async); + + AssertSql( + @"SELECT [e].[Id], [e].[EntityThreeId], [e].[IntValue1], [e].[IntValue2], [s0].[IntValue3], [s].[IntValue4], [e].[StringValue1], [e].[StringValue2], [s0].[StringValue3], [s].[StringValue4], [e].[OwnedReference_Id], [e].[OwnedReference_OwnedIntValue1], [e].[OwnedReference_OwnedIntValue2], [e].[OwnedReference_OwnedIntValue3], [e].[OwnedReference_OwnedIntValue4], [e].[OwnedReference_OwnedStringValue1], [e].[OwnedReference_OwnedStringValue2], [e].[OwnedReference_OwnedStringValue3], [e].[OwnedReference_OwnedStringValue4] +FROM [EntityOne] AS [e] +INNER JOIN [SplitEntityOnePart3] AS [s] ON [e].[Id] = [s].[Id] +INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e].[Id] = [s0].[Id]"); + } + + public override async Task Split_entity_owning_a_collection(bool async) + { + await base.Split_entity_owning_a_collection(async); + + AssertSql( + @"SELECT [e].[Id], [e].[EntityThreeId], [e].[IntValue1], [e].[IntValue2], [s0].[IntValue3], [s].[IntValue4], [e].[StringValue1], [e].[StringValue2], [s0].[StringValue3], [s].[StringValue4], [o].[EntityOneId], [o].[Id], [o].[OwnedIntValue1], [o].[OwnedIntValue2], [o].[OwnedIntValue3], [o].[OwnedIntValue4], [o].[OwnedStringValue1], [o].[OwnedStringValue2], [o].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [EntityOne] AS [e] +INNER JOIN [SplitEntityOnePart3] AS [s] ON [e].[Id] = [s].[Id] +INNER JOIN [SplitEntityOnePart2] AS [s0] ON [e].[Id] = [s0].[Id] +LEFT JOIN [OwnedCollection] AS [o] ON [e].[Id] = [o].[EntityOneId] +ORDER BY [e].[Id], [o].[EntityOneId]"); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Split_entity_owning_a_split_reference_without_table_sharing(bool async) + { + await base.Split_entity_owning_a_split_reference_without_table_sharing(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Split_entity_owning_a_split_collection(bool async) + { + await base.Split_entity_owning_a_split_collection(async); + + AssertSql(); + } + + public override async Task Split_entity_owning_a_split_reference_with_table_sharing_1(bool async) + { + await base.Split_entity_owning_a_split_reference_with_table_sharing_1(async); + + AssertSql( + @"SELECT [s].[Id], [s].[EntityThreeId], [s].[IntValue1], [s].[IntValue2], [s1].[IntValue3], [s0].[IntValue4], [s].[StringValue1], [s].[StringValue2], [s1].[StringValue3], [s0].[StringValue4], [s].[OwnedReference_Id], [s].[OwnedReference_OwnedIntValue1], [s].[OwnedReference_OwnedIntValue2], [s1].[OwnedReference_OwnedIntValue3], [s0].[OwnedReference_OwnedIntValue4], [s].[OwnedReference_OwnedStringValue1], [s].[OwnedReference_OwnedStringValue2], [s1].[OwnedReference_OwnedStringValue3], [s0].[OwnedReference_OwnedStringValue4] +FROM [SplitEntityOnePart1] AS [s] +INNER JOIN [SplitEntityOnePart3] AS [s0] ON [s].[Id] = [s0].[Id] +INNER JOIN [SplitEntityOnePart2] AS [s1] ON [s].[Id] = [s1].[Id]"); } - private void AssertSql(params string[] expected) - => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); + public override async Task Split_entity_owning_a_split_reference_with_table_sharing_2(bool async) + { + await base.Split_entity_owning_a_split_reference_with_table_sharing_2(async); + + AssertSql(); + } + + public override async Task Split_entity_owning_a_split_reference_with_table_sharing_3(bool async) + { + await base.Split_entity_owning_a_split_reference_with_table_sharing_3(async); + + AssertSql(); + } + + public override async Task Split_entity_owning_a_split_reference_with_table_sharing_4(bool async) + { + await base.Split_entity_owning_a_split_reference_with_table_sharing_4(async); + + AssertSql( + @"SELECT [s].[Id], [s].[EntityThreeId], [s].[IntValue1], [s].[IntValue2], [s1].[IntValue3], [s0].[IntValue4], [s].[StringValue1], [s].[StringValue2], [s1].[StringValue3], [s0].[StringValue4], [s].[OwnedReference_Id], [s].[OwnedReference_OwnedIntValue1], [s].[OwnedReference_OwnedIntValue2], [s1].[OwnedReference_OwnedIntValue3], [o].[OwnedIntValue4], [s].[OwnedReference_OwnedStringValue1], [s].[OwnedReference_OwnedStringValue2], [s1].[OwnedReference_OwnedStringValue3], [o].[OwnedStringValue4] +FROM [SplitEntityOnePart1] AS [s] +INNER JOIN [SplitEntityOnePart3] AS [s0] ON [s].[Id] = [s0].[Id] +INNER JOIN [SplitEntityOnePart2] AS [s1] ON [s].[Id] = [s1].[Id] +LEFT JOIN [OwnedReferencePart3] AS [o] ON [s].[Id] = [o].[EntityOneId]"); + } + + public override async Task Split_entity_owning_a_split_reference_with_table_sharing_5(bool async) + { + await base.Split_entity_owning_a_split_reference_with_table_sharing_5(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Split_entity_owning_a_split_reference_with_table_sharing_6(bool async) + { + await base.Split_entity_owning_a_split_reference_with_table_sharing_6(async); + + AssertSql(); + } + + public override async Task Tph_entity_owning_a_split_reference_on_base_with_table_sharing(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_base_with_table_sharing(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [b].[Discriminator], [b].[MiddleValue], [b].[SiblingValue], [b].[LeafValue], [b].[OwnedReference_Id], [b].[OwnedReference_OwnedIntValue1], [b].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [b].[OwnedReference_OwnedStringValue1], [b].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [BaseEntity] AS [b] +LEFT JOIN [OwnedReferencePart4] AS [o] ON [b].[Id] = [o].[BaseEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o0] ON [b].[Id] = [o0].[BaseEntityId]"); + } + + public override async Task Tpt_entity_owning_a_split_reference_on_base_with_table_sharing(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_base_with_table_sharing(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [m].[MiddleValue], [s].[SiblingValue], [l].[LeafValue], CASE + WHEN [l].[Id] IS NOT NULL THEN N'LeafEntity' + WHEN [s].[Id] IS NOT NULL THEN N'SiblingEntity' + WHEN [m].[Id] IS NOT NULL THEN N'MiddleEntity' +END AS [Discriminator], [b].[OwnedReference_Id], [b].[OwnedReference_OwnedIntValue1], [b].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [b].[OwnedReference_OwnedStringValue1], [b].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [BaseEntity] AS [b] +LEFT JOIN [MiddleEntity] AS [m] ON [b].[Id] = [m].[Id] +LEFT JOIN [SiblingEntity] AS [s] ON [b].[Id] = [s].[Id] +LEFT JOIN [LeafEntity] AS [l] ON [b].[Id] = [l].[Id] +LEFT JOIN [OwnedReferencePart4] AS [o] ON [b].[Id] = [o].[BaseEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o0] ON [b].[Id] = [o0].[BaseEntityId]"); + } + + public override async Task Tph_entity_owning_a_split_reference_on_middle_with_table_sharing(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_middle_with_table_sharing(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [b].[Discriminator], [b].[MiddleValue], [b].[SiblingValue], [b].[LeafValue], [b].[OwnedReference_Id], [b].[OwnedReference_OwnedIntValue1], [b].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [b].[OwnedReference_OwnedStringValue1], [b].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [BaseEntity] AS [b] +LEFT JOIN [OwnedReferencePart4] AS [o] ON [b].[Id] = [o].[MiddleEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o0] ON [b].[Id] = [o0].[MiddleEntityId]"); + } + + public override async Task Tpt_entity_owning_a_split_reference_on_middle_with_table_sharing(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_middle_with_table_sharing(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [m].[MiddleValue], [s].[SiblingValue], [l].[LeafValue], CASE + WHEN [l].[Id] IS NOT NULL THEN N'LeafEntity' + WHEN [s].[Id] IS NOT NULL THEN N'SiblingEntity' + WHEN [m].[Id] IS NOT NULL THEN N'MiddleEntity' +END AS [Discriminator], [m].[Id], [m].[OwnedReference_Id], [m].[OwnedReference_OwnedIntValue1], [m].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [m].[OwnedReference_OwnedStringValue1], [m].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [BaseEntity] AS [b] +LEFT JOIN [MiddleEntity] AS [m] ON [b].[Id] = [m].[Id] +LEFT JOIN [SiblingEntity] AS [s] ON [b].[Id] = [s].[Id] +LEFT JOIN [LeafEntity] AS [l] ON [b].[Id] = [l].[Id] +LEFT JOIN [OwnedReferencePart4] AS [o] ON [m].[Id] = [o].[MiddleEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o0] ON [m].[Id] = [o0].[MiddleEntityId]"); + } + + public override async Task Tph_entity_owning_a_split_reference_on_leaf_with_table_sharing(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_leaf_with_table_sharing(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [b].[Discriminator], [b].[MiddleValue], [b].[SiblingValue], [b].[LeafValue], [b].[OwnedReference_Id], [b].[OwnedReference_OwnedIntValue1], [b].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [b].[OwnedReference_OwnedStringValue1], [b].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [BaseEntity] AS [b] +LEFT JOIN [OwnedReferencePart4] AS [o] ON [b].[Id] = [o].[LeafEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o0] ON [b].[Id] = [o0].[LeafEntityId]"); + } + + public override async Task Tpt_entity_owning_a_split_reference_on_leaf_with_table_sharing(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_leaf_with_table_sharing(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [m].[MiddleValue], [s].[SiblingValue], [l].[LeafValue], CASE + WHEN [l].[Id] IS NOT NULL THEN N'LeafEntity' + WHEN [s].[Id] IS NOT NULL THEN N'SiblingEntity' + WHEN [m].[Id] IS NOT NULL THEN N'MiddleEntity' +END AS [Discriminator], [l].[Id], [l].[OwnedReference_Id], [l].[OwnedReference_OwnedIntValue1], [l].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [l].[OwnedReference_OwnedStringValue1], [l].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [BaseEntity] AS [b] +LEFT JOIN [MiddleEntity] AS [m] ON [b].[Id] = [m].[Id] +LEFT JOIN [SiblingEntity] AS [s] ON [b].[Id] = [s].[Id] +LEFT JOIN [LeafEntity] AS [l] ON [b].[Id] = [l].[Id] +LEFT JOIN [OwnedReferencePart4] AS [o] ON [l].[Id] = [o].[LeafEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o0] ON [l].[Id] = [o0].[LeafEntityId]"); + } + + public override async Task Tpc_entity_owning_a_split_reference_on_leaf_with_table_sharing(bool async) + { + await base.Tpc_entity_owning_a_split_reference_on_leaf_with_table_sharing(async); + + AssertSql( + @"SELECT [t].[Id], [t].[BaseValue], [t].[MiddleValue], [t].[SiblingValue], [t].[LeafValue], [t].[Discriminator], [l].[Id], [l].[OwnedReference_Id], [l].[OwnedReference_OwnedIntValue1], [l].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [l].[OwnedReference_OwnedStringValue1], [l].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM ( + SELECT [b].[Id], [b].[BaseValue], NULL AS [MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'BaseEntity' AS [Discriminator] + FROM [BaseEntity] AS [b] + UNION ALL + SELECT [m].[Id], [m].[BaseValue], [m].[MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'MiddleEntity' AS [Discriminator] + FROM [MiddleEntity] AS [m] + UNION ALL + SELECT [s].[Id], [s].[BaseValue], NULL AS [MiddleValue], [s].[SiblingValue], NULL AS [LeafValue], N'SiblingEntity' AS [Discriminator] + FROM [SiblingEntity] AS [s] + UNION ALL + SELECT [l0].[Id], [l0].[BaseValue], [l0].[MiddleValue], NULL AS [SiblingValue], [l0].[LeafValue], N'LeafEntity' AS [Discriminator] + FROM [LeafEntity] AS [l0] +) AS [t] +LEFT JOIN [LeafEntity] AS [l] ON [t].[Id] = [l].[Id] +LEFT JOIN [OwnedReferencePart4] AS [o] ON [l].[Id] = [o].[LeafEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o0] ON [l].[Id] = [o0].[LeafEntityId]"); + } + + public override async Task Tph_entity_owning_a_split_reference_on_base_with_table_sharing_querying_sibling(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_base_with_table_sharing_querying_sibling(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [b].[Discriminator], [b].[SiblingValue], [b].[OwnedReference_Id], [b].[OwnedReference_OwnedIntValue1], [b].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [b].[OwnedReference_OwnedStringValue1], [b].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [BaseEntity] AS [b] +LEFT JOIN [OwnedReferencePart4] AS [o] ON [b].[Id] = [o].[BaseEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o0] ON [b].[Id] = [o0].[BaseEntityId] +WHERE [b].[Discriminator] = N'SiblingEntity'"); + } + + public override async Task Tpt_entity_owning_a_split_reference_on_base_with_table_sharing_querying_sibling(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_base_with_table_sharing_querying_sibling(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [s].[SiblingValue], [b].[OwnedReference_Id], [b].[OwnedReference_OwnedIntValue1], [b].[OwnedReference_OwnedIntValue2], [o0].[OwnedIntValue3], [o].[OwnedIntValue4], [b].[OwnedReference_OwnedStringValue1], [b].[OwnedReference_OwnedStringValue2], [o0].[OwnedStringValue3], [o].[OwnedStringValue4] +FROM [BaseEntity] AS [b] +INNER JOIN [SiblingEntity] AS [s] ON [b].[Id] = [s].[Id] +LEFT JOIN [OwnedReferencePart4] AS [o] ON [b].[Id] = [o].[BaseEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o0] ON [b].[Id] = [o0].[BaseEntityId]"); + } + + public override async Task Tph_entity_owning_a_split_reference_on_middle_with_table_sharing_querying_sibling(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_middle_with_table_sharing_querying_sibling(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [b].[Discriminator], [b].[SiblingValue] +FROM [BaseEntity] AS [b] +WHERE [b].[Discriminator] = N'SiblingEntity'"); + } + + public override async Task Tpt_entity_owning_a_split_reference_on_middle_with_table_sharing_querying_sibling(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_middle_with_table_sharing_querying_sibling(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [s].[SiblingValue] +FROM [BaseEntity] AS [b] +INNER JOIN [SiblingEntity] AS [s] ON [b].[Id] = [s].[Id]"); + } + + public override async Task Tph_entity_owning_a_split_reference_on_leaf_with_table_sharing_querying_sibling(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_leaf_with_table_sharing_querying_sibling(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [b].[Discriminator], [b].[SiblingValue] +FROM [BaseEntity] AS [b] +WHERE [b].[Discriminator] = N'SiblingEntity'"); + } + + public override async Task Tpt_entity_owning_a_split_reference_on_leaf_with_table_sharing_querying_sibling(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_leaf_with_table_sharing_querying_sibling(async); + + AssertSql( + @"SELECT [b].[Id], [b].[BaseValue], [s].[SiblingValue] +FROM [BaseEntity] AS [b] +INNER JOIN [SiblingEntity] AS [s] ON [b].[Id] = [s].[Id]"); + } + + public override async Task Tpc_entity_owning_a_split_reference_on_leaf_with_table_sharing_querying_sibling(bool async) + { + await base.Tpc_entity_owning_a_split_reference_on_leaf_with_table_sharing_querying_sibling(async); + + AssertSql( + @"SELECT [s].[Id], [s].[BaseValue], [s].[SiblingValue] +FROM [SiblingEntity] AS [s]"); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tph_entity_owning_a_split_reference_on_base_without_table_sharing(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_base_without_table_sharing(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tpt_entity_owning_a_split_reference_on_base_without_table_sharing(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_base_without_table_sharing(async); + + AssertSql(); + } + + public override async Task Tpc_entity_owning_a_split_reference_on_base_without_table_sharing(bool async) + { + await base.Tpc_entity_owning_a_split_reference_on_base_without_table_sharing(async); + + AssertSql( + @"SELECT [t].[Id], [t].[BaseValue], [t].[MiddleValue], [t].[SiblingValue], [t].[LeafValue], [t].[Discriminator], [o].[BaseEntityId], [o].[Id], [o].[OwnedIntValue1], [o].[OwnedIntValue2], [o1].[OwnedIntValue3], [o0].[OwnedIntValue4], [o].[OwnedStringValue1], [o].[OwnedStringValue2], [o1].[OwnedStringValue3], [o0].[OwnedStringValue4] +FROM ( + SELECT [b].[Id], [b].[BaseValue], NULL AS [MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'BaseEntity' AS [Discriminator] + FROM [BaseEntity] AS [b] + UNION ALL + SELECT [m].[Id], [m].[BaseValue], [m].[MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'MiddleEntity' AS [Discriminator] + FROM [MiddleEntity] AS [m] + UNION ALL + SELECT [s].[Id], [s].[BaseValue], NULL AS [MiddleValue], [s].[SiblingValue], NULL AS [LeafValue], N'SiblingEntity' AS [Discriminator] + FROM [SiblingEntity] AS [s] + UNION ALL + SELECT [l].[Id], [l].[BaseValue], [l].[MiddleValue], NULL AS [SiblingValue], [l].[LeafValue], N'LeafEntity' AS [Discriminator] + FROM [LeafEntity] AS [l] +) AS [t] +LEFT JOIN [OwnedReferencePart1] AS [o] ON [t].[Id] = [o].[BaseEntityId] +LEFT JOIN [OwnedReferencePart4] AS [o0] ON [o].[BaseEntityId] = [o0].[BaseEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o1] ON [o].[BaseEntityId] = [o1].[BaseEntityId]"); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tph_entity_owning_a_split_reference_on_middle_without_table_sharing(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_middle_without_table_sharing(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tpt_entity_owning_a_split_reference_on_middle_without_table_sharing(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_middle_without_table_sharing(async); + + AssertSql(); + } + + public override async Task Tpc_entity_owning_a_split_reference_on_middle_without_table_sharing(bool async) + { + await base.Tpc_entity_owning_a_split_reference_on_middle_without_table_sharing(async); + + AssertSql( + @"SELECT [t].[Id], [t].[BaseValue], [t].[MiddleValue], [t].[SiblingValue], [t].[LeafValue], [t].[Discriminator], [o].[MiddleEntityId], [o].[Id], [o].[OwnedIntValue1], [o].[OwnedIntValue2], [o1].[OwnedIntValue3], [o0].[OwnedIntValue4], [o].[OwnedStringValue1], [o].[OwnedStringValue2], [o1].[OwnedStringValue3], [o0].[OwnedStringValue4] +FROM ( + SELECT [b].[Id], [b].[BaseValue], NULL AS [MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'BaseEntity' AS [Discriminator] + FROM [BaseEntity] AS [b] + UNION ALL + SELECT [m].[Id], [m].[BaseValue], [m].[MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'MiddleEntity' AS [Discriminator] + FROM [MiddleEntity] AS [m] + UNION ALL + SELECT [s].[Id], [s].[BaseValue], NULL AS [MiddleValue], [s].[SiblingValue], NULL AS [LeafValue], N'SiblingEntity' AS [Discriminator] + FROM [SiblingEntity] AS [s] + UNION ALL + SELECT [l].[Id], [l].[BaseValue], [l].[MiddleValue], NULL AS [SiblingValue], [l].[LeafValue], N'LeafEntity' AS [Discriminator] + FROM [LeafEntity] AS [l] +) AS [t] +LEFT JOIN [OwnedReferencePart1] AS [o] ON [t].[Id] = [o].[MiddleEntityId] +LEFT JOIN [OwnedReferencePart4] AS [o0] ON [o].[MiddleEntityId] = [o0].[MiddleEntityId] +LEFT JOIN [OwnedReferencePart3] AS [o1] ON [o].[MiddleEntityId] = [o1].[MiddleEntityId]"); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tph_entity_owning_a_split_reference_on_leaf_without_table_sharing(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_leaf_without_table_sharing(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tpt_entity_owning_a_split_reference_on_leaf_without_table_sharing(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_leaf_without_table_sharing(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tpc_entity_owning_a_split_reference_on_leaf_without_table_sharing(bool async) + { + await base.Tpc_entity_owning_a_split_reference_on_leaf_without_table_sharing(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tph_entity_owning_a_split_collection_on_base(bool async) + { + await base.Tph_entity_owning_a_split_collection_on_base(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tpt_entity_owning_a_split_collection_on_base(bool async) + { + await base.Tpt_entity_owning_a_split_collection_on_base(async); + + AssertSql(); + } + + public override async Task Tpc_entity_owning_a_split_collection_on_base(bool async) + { + await base.Tpc_entity_owning_a_split_collection_on_base(async); + + AssertSql( + @"SELECT [t].[Id], [t].[BaseValue], [t].[MiddleValue], [t].[SiblingValue], [t].[LeafValue], [t].[Discriminator], [t0].[BaseEntityId], [t0].[Id], [t0].[OwnedIntValue1], [t0].[OwnedIntValue2], [t0].[OwnedIntValue3], [t0].[OwnedIntValue4], [t0].[OwnedStringValue1], [t0].[OwnedStringValue2], [t0].[OwnedStringValue3], [t0].[OwnedStringValue4] +FROM ( + SELECT [b].[Id], [b].[BaseValue], NULL AS [MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'BaseEntity' AS [Discriminator] + FROM [BaseEntity] AS [b] + UNION ALL + SELECT [m].[Id], [m].[BaseValue], [m].[MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'MiddleEntity' AS [Discriminator] + FROM [MiddleEntity] AS [m] + UNION ALL + SELECT [s].[Id], [s].[BaseValue], NULL AS [MiddleValue], [s].[SiblingValue], NULL AS [LeafValue], N'SiblingEntity' AS [Discriminator] + FROM [SiblingEntity] AS [s] + UNION ALL + SELECT [l].[Id], [l].[BaseValue], [l].[MiddleValue], NULL AS [SiblingValue], [l].[LeafValue], N'LeafEntity' AS [Discriminator] + FROM [LeafEntity] AS [l] +) AS [t] +LEFT JOIN ( + SELECT [o].[BaseEntityId], [o].[Id], [o].[OwnedIntValue1], [o].[OwnedIntValue2], [o1].[OwnedIntValue3], [o0].[OwnedIntValue4], [o].[OwnedStringValue1], [o].[OwnedStringValue2], [o1].[OwnedStringValue3], [o0].[OwnedStringValue4] + FROM [OwnedReferencePart1] AS [o] + INNER JOIN [OwnedReferencePart4] AS [o0] ON [o].[BaseEntityId] = [o0].[BaseEntityId] AND [o].[Id] = [o0].[Id] + INNER JOIN [OwnedReferencePart3] AS [o1] ON [o].[BaseEntityId] = [o1].[BaseEntityId] AND [o].[Id] = [o1].[Id] +) AS [t0] ON [t].[Id] = [t0].[BaseEntityId] +ORDER BY [t].[Id], [t0].[BaseEntityId]"); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tph_entity_owning_a_split_collection_on_middle(bool async) + { + await base.Tph_entity_owning_a_split_collection_on_middle(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tpt_entity_owning_a_split_collection_on_middle(bool async) + { + await base.Tpt_entity_owning_a_split_collection_on_middle(async); + + AssertSql(); + } + + public override async Task Tpc_entity_owning_a_split_collection_on_middle(bool async) + { + await base.Tpc_entity_owning_a_split_collection_on_middle(async); + + AssertSql( + @"SELECT [t].[Id], [t].[BaseValue], [t].[MiddleValue], [t].[SiblingValue], [t].[LeafValue], [t].[Discriminator], [t0].[MiddleEntityId], [t0].[Id], [t0].[OwnedIntValue1], [t0].[OwnedIntValue2], [t0].[OwnedIntValue3], [t0].[OwnedIntValue4], [t0].[OwnedStringValue1], [t0].[OwnedStringValue2], [t0].[OwnedStringValue3], [t0].[OwnedStringValue4] +FROM ( + SELECT [b].[Id], [b].[BaseValue], NULL AS [MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'BaseEntity' AS [Discriminator] + FROM [BaseEntity] AS [b] + UNION ALL + SELECT [m].[Id], [m].[BaseValue], [m].[MiddleValue], NULL AS [SiblingValue], NULL AS [LeafValue], N'MiddleEntity' AS [Discriminator] + FROM [MiddleEntity] AS [m] + UNION ALL + SELECT [s].[Id], [s].[BaseValue], NULL AS [MiddleValue], [s].[SiblingValue], NULL AS [LeafValue], N'SiblingEntity' AS [Discriminator] + FROM [SiblingEntity] AS [s] + UNION ALL + SELECT [l].[Id], [l].[BaseValue], [l].[MiddleValue], NULL AS [SiblingValue], [l].[LeafValue], N'LeafEntity' AS [Discriminator] + FROM [LeafEntity] AS [l] +) AS [t] +LEFT JOIN ( + SELECT [o].[MiddleEntityId], [o].[Id], [o].[OwnedIntValue1], [o].[OwnedIntValue2], [o1].[OwnedIntValue3], [o0].[OwnedIntValue4], [o].[OwnedStringValue1], [o].[OwnedStringValue2], [o1].[OwnedStringValue3], [o0].[OwnedStringValue4] + FROM [OwnedReferencePart1] AS [o] + INNER JOIN [OwnedReferencePart4] AS [o0] ON [o].[MiddleEntityId] = [o0].[MiddleEntityId] AND [o].[Id] = [o0].[Id] + INNER JOIN [OwnedReferencePart3] AS [o1] ON [o].[MiddleEntityId] = [o1].[MiddleEntityId] AND [o].[Id] = [o1].[Id] +) AS [t0] ON [t].[Id] = [t0].[MiddleEntityId] +ORDER BY [t].[Id], [t0].[MiddleEntityId]"); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tph_entity_owning_a_split_collection_on_leaf(bool async) + { + await base.Tph_entity_owning_a_split_collection_on_leaf(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tpt_entity_owning_a_split_collection_on_leaf(bool async) + { + await base.Tpt_entity_owning_a_split_collection_on_leaf(async); + + AssertSql(); + } + + [ConditionalTheory(Skip = "Issue29075")] + public override async Task Tpc_entity_owning_a_split_collection_on_leaf(bool async) + { + await base.Tpc_entity_owning_a_split_collection_on_leaf(async); + + AssertSql(); + } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/InheritanceRelationshipsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/InheritanceRelationshipsQuerySqlServerTest.cs index 0b074b52af5..5e45f559791 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/InheritanceRelationshipsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/InheritanceRelationshipsQuerySqlServerTest.cs @@ -50,10 +50,10 @@ public override async Task Include_self_reference_with_inheritance(bool async) await base.Include_self_reference_with_inheritance(async); AssertSql( - @"SELECT [b].[Id], [b].[Discriminator], [b].[Name], [b].[BaseId], [t].[Id], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [b2].[DerivedInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [b].[OwnedReferenceOnDerived_Id], [b].[OwnedReferenceOnDerived_Name], [t].[Discriminator], [t].[Name], [t].[BaseId], [b3].[BaseInheritanceRelationshipEntityId], [b3].[Id], [b3].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b4].[DerivedInheritanceRelationshipEntityId], [b4].[Id], [b4].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [b].[Id], [b].[Discriminator], [b].[Name], [b].[BaseId], [t].[Id], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [b2].[DerivedInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [b].[OwnedReferenceOnDerived_Id], [b].[OwnedReferenceOnDerived_Name], [t].[Discriminator], [t].[Name], [t].[BaseId], [b3].[BaseInheritanceRelationshipEntityId], [b3].[Id], [b3].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b4].[DerivedInheritanceRelationshipEntityId], [b4].[Id], [b4].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] WHERE [b0].[Discriminator] = N'DerivedInheritanceRelationshipEntity' ) AS [t] ON [b].[Id] = [t].[BaseId] @@ -321,10 +321,10 @@ public override async Task Include_reference_with_inheritance_on_derived_reverse await base.Include_reference_with_inheritance_on_derived_reverse(async); AssertSql( - @"SELECT [b].[Id], [b].[BaseParentId], [b].[Discriminator], [b].[Name], [b].[DerivedInheritanceRelationshipEntityId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b2].[DerivedInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [b].[Id], [b].[BaseParentId], [b].[Discriminator], [b].[Name], [b].[DerivedInheritanceRelationshipEntityId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b2].[DerivedInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseReferencesOnDerived] AS [b] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] WHERE [b0].[Discriminator] = N'DerivedInheritanceRelationshipEntity' ) AS [t] ON [b].[BaseParentId] = [t].[Id] @@ -384,10 +384,10 @@ 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 [b].[Id], [b].[BaseParentId], [b].[Discriminator], [b].[Name], [b].[DerivedInheritanceRelationshipEntityId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b2].[DerivedInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [b].[Id], [b].[BaseParentId], [b].[Discriminator], [b].[Name], [b].[DerivedInheritanceRelationshipEntityId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b2].[DerivedInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseReferencesOnDerived] AS [b] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] WHERE [b0].[Discriminator] = N'DerivedInheritanceRelationshipEntity' ) AS [t] ON [b].[BaseParentId] = [t].[Id] @@ -430,10 +430,10 @@ public override async Task Include_reference_without_inheritance_on_derived_reve await base.Include_reference_without_inheritance_on_derived_reverse(async); AssertSql( - @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b1].[DerivedInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b1].[DerivedInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [ReferencesOnDerived] AS [r] LEFT JOIN ( - SELECT [b].[Id], [b].[Discriminator], [b].[Name], [b].[BaseId], [b].[Id] AS [Id0], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [b].[OwnedReferenceOnDerived_Id], [b].[OwnedReferenceOnDerived_Name] + SELECT [b].[Id], [b].[Discriminator], [b].[Name], [b].[BaseId], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [b].[OwnedReferenceOnDerived_Id], [b].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] WHERE [b].[Discriminator] = N'DerivedInheritanceRelationshipEntity' ) AS [t] ON [r].[ParentId] = [t].[Id] @@ -493,10 +493,10 @@ public override async Task Include_collection_with_inheritance_on_derived_revers await base.Include_collection_with_inheritance_on_derived_reverse(async); AssertSql( - @"SELECT [b].[Id], [b].[Discriminator], [b].[Name], [b].[ParentId], [b].[DerivedInheritanceRelationshipEntityId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b2].[DerivedInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [b].[Id], [b].[Discriminator], [b].[Name], [b].[ParentId], [b].[DerivedInheritanceRelationshipEntityId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [b2].[DerivedInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseCollectionsOnDerived] AS [b] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] WHERE [b0].[Discriminator] = N'DerivedInheritanceRelationshipEntity' ) AS [t] ON [b].[ParentId] = [t].[Id] @@ -999,16 +999,16 @@ public override async Task Include_collection_with_inheritance_on_derived_revers await base.Include_collection_with_inheritance_on_derived_reverse_split(async); AssertSql( - @"SELECT [b].[Id], [b].[Discriminator], [b].[Name], [b].[ParentId], [b].[DerivedInheritanceRelationshipEntityId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [b].[Id], [b].[Discriminator], [b].[Name], [b].[ParentId], [b].[DerivedInheritanceRelationshipEntityId], [t].[Id], [t].[Discriminator], [t].[Name], [t].[BaseId], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseCollectionsOnDerived] AS [b] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Discriminator], [b0].[Name], [b0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [b0].[OwnedReferenceOnDerived_Id], [b0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] WHERE [b0].[Discriminator] = N'DerivedInheritanceRelationshipEntity' ) AS [t] ON [b].[ParentId] = [t].[Id] ORDER BY [b].[Id], [t].[Id]", - // - @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] + // + @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] FROM [BaseCollectionsOnDerived] AS [b] LEFT JOIN ( SELECT [b0].[Id] @@ -1017,8 +1017,8 @@ FROM [BaseEntities] AS [b0] ) AS [t] ON [b].[ParentId] = [t].[Id] INNER JOIN [BaseEntities_OwnedCollectionOnBase] AS [b1] ON [t].[Id] = [b1].[BaseInheritanceRelationshipEntityId] ORDER BY [b].[Id], [t].[Id]", - // - @"SELECT [b1].[DerivedInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] + // + @"SELECT [b1].[DerivedInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] FROM [BaseCollectionsOnDerived] AS [b] LEFT JOIN ( SELECT [b0].[Id] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/OwnedEntityQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/OwnedEntityQuerySqlServerTest.cs index f87d95e9359..e013a6e95c1 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/OwnedEntityQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/OwnedEntityQuerySqlServerTest.cs @@ -106,16 +106,12 @@ public override async Task Owned_reference_mapped_to_different_table_updated_cor AssertSql( @"@__p_0='10' -SELECT [t].[Id], [t].[Name], [t].[CompanyId], [t].[AdditionalCustomerData], [t].[Id0], [s].[CompanyId], [s].[AdditionalSupplierData], [s].[Id] -FROM ( - SELECT TOP(@__p_0) [c].[Id], [c].[Name], [c0].[CompanyId], [c0].[AdditionalCustomerData], [c0].[Id] AS [Id0] - FROM [Companies] AS [c] - LEFT JOIN [CustomerData] AS [c0] ON [c].[Id] = [c0].[CompanyId] - WHERE [c0].[CompanyId] IS NOT NULL - ORDER BY [c].[Id] -) AS [t] -LEFT JOIN [SupplierData] AS [s] ON [t].[Id] = [s].[CompanyId] -ORDER BY [t].[Id]"); +SELECT TOP(@__p_0) [c].[Id], [c].[Name], [c0].[CompanyId], [c0].[AdditionalCustomerData], [c0].[Id], [s].[CompanyId], [s].[AdditionalSupplierData], [s].[Id] +FROM [Companies] AS [c] +LEFT JOIN [CustomerData] AS [c0] ON [c].[Id] = [c0].[CompanyId] +LEFT JOIN [SupplierData] AS [s] ON [c].[Id] = [s].[CompanyId] +WHERE [c0].[CompanyId] IS NOT NULL +ORDER BY [c].[Id]"); } public override async Task Owned_reference_mapped_to_different_table_nested_updated_correctly_after_subquery_pushdown(bool async) @@ -125,17 +121,13 @@ public override async Task Owned_reference_mapped_to_different_table_nested_upda AssertSql( @"@__p_0='10' -SELECT [t].[Id], [t].[Name], [t].[OwnerId], [t].[Id0], [t].[Name0], [t].[IntermediateOwnedEntityOwnerId], [t].[AdditionalCustomerData], [t].[Id1], [i1].[IntermediateOwnedEntityOwnerId], [i1].[AdditionalSupplierData], [i1].[Id] -FROM ( - SELECT TOP(@__p_0) [o].[Id], [o].[Name], [i].[OwnerId], [i].[Id] AS [Id0], [i].[Name] AS [Name0], [i0].[IntermediateOwnedEntityOwnerId], [i0].[AdditionalCustomerData], [i0].[Id] AS [Id1] - FROM [Owners] AS [o] - LEFT JOIN [IntermediateOwnedEntity] AS [i] ON [o].[Id] = [i].[OwnerId] - LEFT JOIN [IM_CustomerData] AS [i0] ON [i].[OwnerId] = [i0].[IntermediateOwnedEntityOwnerId] - WHERE [i0].[IntermediateOwnedEntityOwnerId] IS NOT NULL - ORDER BY [o].[Id] -) AS [t] -LEFT JOIN [IM_SupplierData] AS [i1] ON [t].[OwnerId] = [i1].[IntermediateOwnedEntityOwnerId] -ORDER BY [t].[Id]"); +SELECT TOP(@__p_0) [o].[Id], [o].[Name], [i].[OwnerId], [i].[Id], [i].[Name], [i0].[IntermediateOwnedEntityOwnerId], [i0].[AdditionalCustomerData], [i0].[Id], [i1].[IntermediateOwnedEntityOwnerId], [i1].[AdditionalSupplierData], [i1].[Id] +FROM [Owners] AS [o] +LEFT JOIN [IntermediateOwnedEntity] AS [i] ON [o].[Id] = [i].[OwnerId] +LEFT JOIN [IM_CustomerData] AS [i0] ON [i].[OwnerId] = [i0].[IntermediateOwnedEntityOwnerId] +LEFT JOIN [IM_SupplierData] AS [i1] ON [i].[OwnerId] = [i1].[IntermediateOwnedEntityOwnerId] +WHERE [i0].[IntermediateOwnedEntityOwnerId] IS NOT NULL +ORDER BY [o].[Id]"); } public override async Task Owned_entity_with_all_null_properties_materializes_when_not_containing_another_owned_entity(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs index 01c5a88eee6..20632fbb23e 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs @@ -1123,44 +1123,20 @@ public override async Task Using_from_sql_on_owner_generates_join_with_table_for await base.Using_from_sql_on_owner_generates_join_with_table_for_owned_shared_dependents(async); AssertSql( - @"SELECT [m].[Id], [m].[Discriminator], [m].[Name], [t].[Id], [t0].[Id], [t1].[Id], [t2].[Id], [t3].[ClientId], [t3].[Id], [t3].[OrderDate], [t3].[OrderClientId], [t3].[OrderId], [t3].[Id0], [t3].[Detail], [t].[PersonAddress_AddressLine], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[Id0], [t].[PersonAddress_Country_Name], [t].[PersonAddress_Country_PlanetId], [t0].[BranchAddress_BranchName], [t0].[BranchAddress_PlaceType], [t0].[Id0], [t0].[BranchAddress_Country_Name], [t0].[BranchAddress_Country_PlanetId], [t1].[LeafBAddress_LeafBType], [t1].[LeafBAddress_PlaceType], [t1].[Id0], [t1].[LeafBAddress_Country_Name], [t1].[LeafBAddress_Country_PlanetId], [t2].[LeafAAddress_LeafType], [t2].[LeafAAddress_PlaceType], [t2].[Id0], [t2].[LeafAAddress_Country_Name], [t2].[LeafAAddress_Country_PlanetId] + @"SELECT [m].[Id], [m].[Discriminator], [m].[Name], [o].[Id], [o0].[Id], [o1].[Id], [o2].[Id], [t].[ClientId], [t].[Id], [t].[OrderDate], [t].[OrderClientId], [t].[OrderId], [t].[Id0], [t].[Detail], [o].[PersonAddress_AddressLine], [o].[PersonAddress_PlaceType], [o].[PersonAddress_ZipCode], [o].[PersonAddress_Country_Name], [o].[PersonAddress_Country_PlanetId], [o0].[BranchAddress_BranchName], [o0].[BranchAddress_PlaceType], [o0].[BranchAddress_Country_Name], [o0].[BranchAddress_Country_PlanetId], [o1].[LeafBAddress_LeafBType], [o1].[LeafBAddress_PlaceType], [o1].[LeafBAddress_Country_Name], [o1].[LeafBAddress_Country_PlanetId], [o2].[LeafAAddress_LeafType], [o2].[LeafAAddress_PlaceType], [o2].[LeafAAddress_Country_Name], [o2].[LeafAAddress_Country_PlanetId] FROM ( SELECT * FROM ""OwnedPerson"" ) AS [m] -LEFT JOIN ( - SELECT [o].[Id], [o].[PersonAddress_AddressLine], [o].[PersonAddress_PlaceType], [o].[PersonAddress_ZipCode], [o].[Id] AS [Id0], [o].[PersonAddress_Country_Name], [o].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o] - WHERE [o].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [m].[Id] = CASE - WHEN [t].[PersonAddress_ZipCode] IS NOT NULL THEN [t].[Id] -END -LEFT JOIN ( - SELECT [o0].[Id], [o0].[BranchAddress_BranchName], [o0].[BranchAddress_PlaceType], [o0].[Id] AS [Id0], [o0].[BranchAddress_Country_Name], [o0].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[BranchAddress_BranchName] IS NOT NULL -) AS [t0] ON [m].[Id] = CASE - WHEN [t0].[BranchAddress_BranchName] IS NOT NULL THEN [t0].[Id] -END -LEFT JOIN ( - SELECT [o1].[Id], [o1].[LeafBAddress_LeafBType], [o1].[LeafBAddress_PlaceType], [o1].[Id] AS [Id0], [o1].[LeafBAddress_Country_Name], [o1].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[LeafBAddress_LeafBType] IS NOT NULL -) AS [t1] ON [m].[Id] = CASE - WHEN [t1].[LeafBAddress_LeafBType] IS NOT NULL THEN [t1].[Id] -END -LEFT JOIN ( - SELECT [o2].[Id], [o2].[LeafAAddress_LeafType], [o2].[LeafAAddress_PlaceType], [o2].[Id] AS [Id0], [o2].[LeafAAddress_Country_Name], [o2].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[LeafAAddress_LeafType] IS NOT NULL -) AS [t2] ON [m].[Id] = CASE - WHEN [t2].[LeafAAddress_LeafType] IS NOT NULL THEN [t2].[Id] -END +LEFT JOIN [OwnedPerson] AS [o] ON [m].[Id] = [o].[Id] +LEFT JOIN [OwnedPerson] AS [o0] ON [m].[Id] = [o0].[Id] +LEFT JOIN [OwnedPerson] AS [o1] ON [m].[Id] = [o1].[Id] +LEFT JOIN [OwnedPerson] AS [o2] ON [m].[Id] = [o2].[Id] LEFT JOIN ( SELECT [o3].[ClientId], [o3].[Id], [o3].[OrderDate], [o4].[OrderClientId], [o4].[OrderId], [o4].[Id] AS [Id0], [o4].[Detail] FROM [Order] AS [o3] LEFT JOIN [OrderDetail] AS [o4] ON [o3].[ClientId] = [o4].[OrderClientId] AND [o3].[Id] = [o4].[OrderId] -) AS [t3] ON [m].[Id] = [t3].[ClientId] -ORDER BY [m].[Id], [t].[Id], [t0].[Id], [t1].[Id], [t2].[Id], [t3].[ClientId], [t3].[Id], [t3].[OrderClientId], [t3].[OrderId]"); +) AS [t] ON [m].[Id] = [t].[ClientId] +ORDER BY [m].[Id], [o].[Id], [o0].[Id], [o1].[Id], [o2].[Id], [t].[ClientId], [t].[Id], [t].[OrderClientId], [t].[OrderId]"); } public override async Task Projecting_collection_correlated_with_keyless_entity_after_navigation_works_using_parent_identifiers( diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPCRelationshipsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPCRelationshipsQuerySqlServerTest.cs index 8e4833e2e04..c24b2bf86cc 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPCRelationshipsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPCRelationshipsQuerySqlServerTest.cs @@ -24,9 +24,9 @@ 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name], [t2].[Id], [t2].[BaseParentId], [t2].[Name], [t2].[DerivedProperty], [t2].[Discriminator] + @"SELECT [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [t0].[BaseInheritanceRelationshipEntityId], [t0].[Id1], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t0].[Id0], [t0].[Name0], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[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] + SELECT TOP(2) [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [o].[Id] AS [Id0], [o].[Name] AS [Name0], [d].[Id] AS [Id1], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b0].[Id], [b0].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b0] @@ -35,25 +35,19 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) AS [t] 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 + LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] WHERE [t].[Name] = N'Derived1(4)' -) AS [t1] -LEFT JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] +) AS [t0] +LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] +LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t0].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] UNION ALL 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); +) AS [t1] ON [t0].[Id] = [t1].[BaseParentId] +ORDER BY [t0].[Id], [t0].[BaseInheritanceRelationshipEntityId], [t0].[Id1], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_without_inheritance(bool async) @@ -61,7 +55,7 @@ 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [c].[Id], [c].[Name], [c].[ParentId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[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] @@ -70,17 +64,11 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_without_inheritance_reverse(bool async) @@ -88,7 +76,7 @@ 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], [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] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] @@ -98,16 +86,10 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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]"); +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_collection_without_inheritance_with_filter(bool async) @@ -115,7 +97,7 @@ 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [c].[Id], [c].[Name], [c].[ParentId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[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] @@ -124,18 +106,12 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_without_inheritance_with_filter_reverse(bool async) @@ -143,7 +119,7 @@ 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], [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] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] @@ -153,17 +129,11 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_collection_with_inheritance(bool async) @@ -171,7 +141,7 @@ 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[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], [d].[Id], [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] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -180,13 +150,7 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( @@ -195,8 +159,8 @@ 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] ON [t].[Id] = [t1].[BaseParentId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); +) AS [t0] ON [t].[Id] = [t0].[BaseParentId] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_with_inheritance_on_derived1(bool async) @@ -204,7 +168,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], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[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].[Id], [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] @@ -224,7 +188,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], [t].[Id], [t].[Name], [t].[ParentId], [t].[DerivedInheritanceRelationshipEntityId], [t].[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].[Id], [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] @@ -244,7 +208,7 @@ public override async Task Include_collection_with_inheritance_on_derived3(bool await base.Include_collection_with_inheritance_on_derived3(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], [d1].[Id], [d1].[Name], [d1].[ParentId], [d1].[DerivedInheritanceRelationshipEntityId] + @"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].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [d1].[Id], [d1].[Name], [d1].[ParentId], [d1].[DerivedInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] LEFT JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] @@ -278,7 +242,7 @@ 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], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [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 [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] @@ -294,16 +258,10 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[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 [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_collection_with_inheritance_with_filter(bool async) @@ -311,7 +269,7 @@ 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[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], [d].[Id], [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] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -320,13 +278,7 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( @@ -335,9 +287,9 @@ 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] ON [t].[Id] = [t1].[BaseParentId] +) AS [t0] ON [t].[Id] = [t0].[BaseParentId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_with_inheritance_with_filter_reverse(bool async) @@ -345,7 +297,7 @@ 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], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [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 [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] @@ -361,17 +313,11 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[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 [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_without_inheritance(bool async) @@ -379,7 +325,7 @@ 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -389,16 +335,10 @@ 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 [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 [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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]"); +ORDER BY [t].[Id], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_without_inheritance_on_derived1(bool async) @@ -406,7 +346,7 @@ public override async Task Include_reference_without_inheritance_on_derived1(boo await base.Include_reference_without_inheritance_on_derived1(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [r].[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], [r].[Name], [r].[ParentId] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] FROM [DerivedEntities] AS [d] LEFT JOIN [ReferencesOnBase] AS [r] ON [d].[Id] = [r].[ParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] @@ -420,7 +360,7 @@ public override async Task Include_reference_without_inheritance_on_derived2(boo await base.Include_reference_without_inheritance_on_derived2(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [r].[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], [r].[Name], [r].[ParentId] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] FROM [DerivedEntities] AS [d] LEFT JOIN [ReferencesOnDerived] AS [r] ON [d].[Id] = [r].[ParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] @@ -448,7 +388,7 @@ 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], [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] + @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [ReferencesOnBase] AS [r] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] @@ -458,16 +398,10 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] ON [r].[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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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]"); +ORDER BY [r].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_without_inheritance_with_filter(bool async) @@ -475,7 +409,7 @@ 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [r].[Name], [r].[ParentId] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -485,17 +419,11 @@ 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 [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 [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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], [d0].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [t].[Id], [r].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_without_inheritance_with_filter_reverse(bool async) @@ -503,7 +431,7 @@ 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], [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] + @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [ReferencesOnBase] AS [r] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] @@ -513,17 +441,11 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] ON [r].[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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [r].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance(bool async) @@ -531,7 +453,7 @@ 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], [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] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[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] @@ -547,16 +469,10 @@ UNION ALL FROM [DerivedReferencesOnBase] AS [d2] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] 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 [t1] ON [t].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_on_derived1(bool async) @@ -564,7 +480,7 @@ 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], [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] + @"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].[Id], [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] @@ -584,7 +500,7 @@ 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], [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] + @"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].[Id], [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] @@ -604,7 +520,7 @@ public override async Task Include_reference_with_inheritance_on_derived4(bool a await base.Include_reference_with_inheritance_on_derived4(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [d0].[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], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedInheritanceRelationshipEntityId] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [DerivedReferencesOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] @@ -638,7 +554,7 @@ 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], [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] + @"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].[Id], [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] @@ -659,7 +575,7 @@ 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], [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] + @"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].[Id], [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] @@ -680,7 +596,7 @@ public override async Task Include_reference_with_inheritance_on_derived_with_fi await base.Include_reference_with_inheritance_on_derived_with_filter4(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [d0].[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], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedInheritanceRelationshipEntityId] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [d0].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [d0].[BaseParentId], [d0].[Name], [d0].[DerivedInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [DerivedReferencesOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] @@ -716,7 +632,7 @@ 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], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [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], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] @@ -732,16 +648,10 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[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 [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_with_filter(bool async) @@ -749,7 +659,7 @@ 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], [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] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[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] @@ -765,17 +675,11 @@ UNION ALL FROM [DerivedReferencesOnBase] AS [d2] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] 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 [t1] ON [t].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_reference_with_inheritance_with_filter_reverse(bool async) @@ -783,7 +687,7 @@ 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], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [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], N'BaseReferenceOnBase' AS [Discriminator] FROM [BaseReferencesOnBase] AS [b] @@ -799,17 +703,11 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[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 [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Include_self_reference_with_inheritance(bool async) @@ -817,7 +715,7 @@ 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], [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] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [d].[Id], [o].[BaseInheritanceRelationshipEntityId], [d0].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [o1].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d0].[OwnedReferenceOnDerived_Id], [d0].[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] @@ -827,19 +725,13 @@ FROM [DerivedEntities] AS [d3] ) AS [t] LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[BaseId] 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 [t0] ON [t].[Id] = CASE - WHEN [t0].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t0].[Id] -END +LEFT JOIN [DerivedEntities] AS [d0] ON [t].[Id] = [d0].[Id] 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 [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]"); +ORDER BY [t].[Id], [d].[Id], [o].[BaseInheritanceRelationshipEntityId], [d0].[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,7 +739,7 @@ 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], [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] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [d0].[Id], [o1].[BaseInheritanceRelationshipEntityId], [o1].[Id], [o1].[Name], [o].[Id], [o].[Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[Id], [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], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [DerivedEntities] AS [d] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] @@ -858,18 +750,12 @@ 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 [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -LEFT JOIN ( - 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 [DerivedEntities] AS [d0] ON [t].[Id] = [d0].[Id] LEFT JOIN [OwnedCollections] AS [o1] ON [d].[Id] = [o1].[BaseInheritanceRelationshipEntityId] 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]"); +ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o0].[BaseInheritanceRelationshipEntityId], [d0].[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,7 +778,7 @@ 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], [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] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[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] @@ -901,33 +787,27 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( - 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] + SELECT [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t2].[Id] AS [Id0], [t2].[Name] AS [Name0], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[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 [t2] + ) AS [t0] 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 [t2].[Id] = [t3].[ParentCollectionId] + ) AS [t2] ON [t0].[Id] = [t2].[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]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[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 +815,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], [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] + @"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], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] @@ -958,16 +838,10 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] 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]"); +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_collection_reference(bool async) @@ -975,7 +849,7 @@ 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], [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] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[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] @@ -984,33 +858,27 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( - 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] + SELECT [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t2].[Id] AS [Id0], [t2].[Name] AS [Name0], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[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 [t2] + ) AS [t0] 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 [t2].[Id] = [t3].[ParentCollectionId] + ) AS [t2] ON [t0].[Id] = [t2].[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]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[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 +886,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], [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] + @"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], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] FROM [NestedReferences] AS [n] @@ -1041,16 +909,10 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] 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]"); +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_reference_collection(bool async) @@ -1058,7 +920,7 @@ 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], [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] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator], [t1].[Id], [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] @@ -1074,13 +936,7 @@ UNION ALL FROM [DerivedReferencesOnBase] AS [d2] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] 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 [t1] ON [t].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] LEFT JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] LEFT JOIN ( @@ -1089,8 +945,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 [t2] ON [t0].[Id] = [t2].[ParentReferenceId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); +) AS [t1] ON [t0].[Id] = [t1].[ParentReferenceId] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Nested_include_with_inheritance_reference_collection_on_base(bool async) @@ -1098,7 +954,7 @@ 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], [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] + @"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].[Id], [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] @@ -1125,7 +981,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], [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] + @"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], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] @@ -1148,16 +1004,10 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] 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]"); +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_reference_reference(bool async) @@ -1165,7 +1015,7 @@ 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], [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] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[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] @@ -1188,16 +1038,10 @@ UNION ALL FROM [NestedReferencesDerived] AS [n0] ) AS [t1] ON [t0].[Id] = [t1].[ParentReferenceId] 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 [t2] ON [t].[Id] = CASE - WHEN [t2].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t2].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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]"); +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Nested_include_with_inheritance_reference_reference_on_base(bool async) @@ -1205,7 +1049,7 @@ 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], [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] + @"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].[Id], [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] @@ -1232,7 +1076,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], [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] + @"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], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] FROM [NestedReferences] AS [n] @@ -1255,16 +1099,10 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] 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]"); +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId]"); } public override async Task Collection_projection_on_base_type(bool async) @@ -1295,7 +1133,7 @@ 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name], [d1].[Id], [d1].[Name], [d1].[ParentId], [d1].[DerivedInheritanceRelationshipEntityId] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [o].[Id], [o].[Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[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] @@ -1304,18 +1142,12 @@ UNION ALL FROM [DerivedEntities] AS [d2] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] LEFT JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] 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], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id]"); } public override async Task Include_collection_with_inheritance_split(bool async) @@ -1323,7 +1155,7 @@ public override async Task Include_collection_with_inheritance_split(bool async) await base.Include_collection_with_inheritance_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -1332,16 +1164,10 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -1350,17 +1176,11 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -1369,17 +1189,11 @@ SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -1388,21 +1202,15 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN ( 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] ON [t].[Id] = [t1].[BaseParentId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); +) AS [t0] ON [t].[Id] = [t0].[BaseParentId] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Include_collection_with_inheritance_reverse_split(bool async) @@ -1410,7 +1218,7 @@ 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], [t1].[Id], [o].[Id], [o].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] @@ -1426,16 +1234,10 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[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 [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseCollectionsOnBase] AS [b] @@ -1451,17 +1253,11 @@ 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 [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 +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t0].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[BaseParentId] FROM [BaseCollectionsOnBase] AS [b] @@ -1477,15 +1273,9 @@ 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 [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 +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t0].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Include_collection_with_inheritance_with_filter_split(bool async) @@ -1493,7 +1283,7 @@ public override async Task Include_collection_with_inheritance_with_filter_split await base.Include_collection_with_inheritance_with_filter_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -1502,17 +1292,11 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] @@ -1521,18 +1305,12 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] @@ -1541,18 +1319,12 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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]", - // - @"SELECT [t1].[Id], [t1].[BaseParentId], [t1].[Name], [t1].[DerivedProperty], [t1].[Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] @@ -1561,22 +1333,16 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN ( 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] ON [t].[Id] = [t1].[BaseParentId] +) AS [t0] ON [t].[Id] = [t0].[BaseParentId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Include_collection_with_inheritance_with_filter_reverse_split(bool async) @@ -1584,7 +1350,7 @@ 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], [t1].[Id], [o].[Id], [o].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name], NULL AS [DerivedProperty], N'BaseCollectionOnBase' AS [Discriminator] FROM [BaseCollectionsOnBase] AS [b] @@ -1600,17 +1366,11 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] LEFT JOIN [OwnedReferences] AS [o] ON [t0].[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 [t1] ON [t0].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name] FROM [BaseCollectionsOnBase] AS [b] @@ -1626,18 +1386,12 @@ 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 [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 +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] 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], [t1].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[BaseParentId], [b].[Name] FROM [BaseCollectionsOnBase] AS [b] @@ -1653,16 +1407,10 @@ 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 [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 +LEFT JOIN [DerivedEntities] AS [d] ON [t0].[Id] = [d].[Id] 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], [t1].[Id]"); +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Include_collection_without_inheritance_split(bool async) @@ -1670,7 +1418,7 @@ public override async Task Include_collection_without_inheritance_split(bool asy await base.Include_collection_without_inheritance_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -1679,16 +1427,10 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -1697,17 +1439,11 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -1716,17 +1452,11 @@ SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -1735,15 +1465,9 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [CollectionsOnBase] AS [c] ON [t].[Id] = [c].[ParentId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Include_collection_without_inheritance_reverse_split(bool async) @@ -1751,7 +1475,7 @@ 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], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] @@ -1761,16 +1485,10 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) 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], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] @@ -1780,17 +1498,11 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] @@ -1800,15 +1512,9 @@ 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 [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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] -ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Include_collection_without_inheritance_with_filter_split(bool async) @@ -1816,7 +1522,7 @@ public override async Task Include_collection_without_inheritance_with_filter_sp await base.Include_collection_without_inheritance_with_filter_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -1825,17 +1531,11 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] @@ -1844,18 +1544,12 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] WHERE [t].[Name] <> N'Bar' OR [t].[Name] IS NULL -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] @@ -1864,18 +1558,12 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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]", - // - @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id], [b].[Name] FROM [BaseEntities] AS [b] @@ -1884,16 +1572,10 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER 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]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Include_collection_without_inheritance_with_filter_reverse_split(bool async) @@ -1901,7 +1583,7 @@ 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], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] @@ -1911,17 +1593,11 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] WHERE [c].[Name] <> N'Bar' OR [c].[Name] IS NULL -ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] @@ -1931,18 +1607,12 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] WHERE [c].[Name] <> N'Bar' OR [c].[Name] IS NULL -ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] @@ -1952,16 +1622,10 @@ 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 [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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); +ORDER BY [c].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Include_collection_with_inheritance_on_derived1_split(bool async) @@ -1969,24 +1633,24 @@ public override async Task Include_collection_with_inheritance_on_derived1_split await base.Include_collection_with_inheritance_on_derived1_split(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[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 ( @@ -2003,24 +1667,24 @@ public override async Task Include_collection_with_inheritance_on_derived2_split { await base.Include_collection_with_inheritance_on_derived2_split(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [t].[Id], [t].[Name], [t].[ParentId], [t].[DerivedInheritanceRelationshipEntityId], [t].[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 ( @@ -2038,24 +1702,24 @@ public override async Task Include_collection_with_inheritance_on_derived3_split await base.Include_collection_with_inheritance_on_derived3_split(async); AssertSql( - @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [d].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [d0].[Id], [d0].[Name], [d0].[ParentId], [d0].[DerivedInheritanceRelationshipEntityId], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] + // + @"SELECT [d0].[Id], [d0].[Name], [d0].[ParentId], [d0].[DerivedInheritanceRelationshipEntityId], [d].[Id], [o].[BaseInheritanceRelationshipEntityId] FROM [DerivedEntities] AS [d] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [DerivedCollectionsOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] @@ -2111,7 +1775,7 @@ 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], [t1].[Id], [o].[Id], [o].[Name], [t1].[OwnedReferenceOnDerived_Id], [t1].[OwnedReferenceOnDerived_Name], [t0].[BaseParentId], [t0].[Name], [t0].[Discriminator] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[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] @@ -2127,16 +1791,10 @@ UNION ALL FROM [DerivedReferencesOnBase] AS [d1] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] 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 [t1] ON [t].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2152,17 +1810,11 @@ UNION ALL FROM [DerivedReferencesOnBase] AS [d1] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] 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 [t1] ON [t].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2178,17 +1830,11 @@ UNION ALL FROM [DerivedReferencesOnBase] AS [d2] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] 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 [t1] ON [t].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]", - // - @"SELECT [t2].[Id], [t2].[Name], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[Discriminator], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [t1].[Id], [t1].[Name], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator], [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2204,21 +1850,15 @@ UNION ALL FROM [DerivedReferencesOnBase] AS [d1] ) AS [t0] ON [t].[Id] = [t0].[BaseParentId] 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 [t1] ON [t].[Id] = CASE - WHEN [t1].[OwnedReferenceOnDerived_Id] IS NOT NULL THEN [t1].[Id] -END +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER 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 [t2] ON [t0].[Id] = [t2].[ParentReferenceId] -ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [t1].[Id]"); +) AS [t1] ON [t0].[Id] = [t1].[ParentReferenceId] +ORDER BY [t].[Id], [t0].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Nested_include_with_inheritance_reference_collection_on_base_split(bool async) @@ -2226,7 +1866,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], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[BaseParentId], [t].[Name], [t].[Discriminator] + @"SELECT [d].[Id], [d].[Name], [d].[BaseId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [o].[Id], [o].[Name], [d].[Id], [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] @@ -2237,8 +1877,8 @@ FROM [DerivedReferencesOnBase] AS [d0] ) AS [t] ON [d].[Id] = [t].[BaseParentId] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [d].[Id], [t].[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] @@ -2250,8 +1890,8 @@ FROM [DerivedReferencesOnBase] AS [d0] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [OwnedCollections] AS [o0] ON [d].[Id] = [o0].[BaseInheritanceRelationshipEntityId] ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [d].[Id], [t].[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] @@ -2263,8 +1903,8 @@ FROM [DerivedReferencesOnBase] AS [d1] LEFT JOIN [OwnedReferences] AS [o] ON [d].[Id] = [o].[BaseInheritanceRelationshipEntityId] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [d].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] ORDER BY [d].[Id], [t].[Id], [o].[BaseInheritanceRelationshipEntityId]", - // - @"SELECT [t0].[Id], [t0].[Name], [t0].[ParentCollectionId], [t0].[ParentReferenceId], [t0].[Discriminator], [d].[Id], [t].[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] @@ -2289,7 +1929,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], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o].[Id], [o].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[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], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] @@ -2312,16 +1952,10 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) 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], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [n].[Id], [n].[ParentReferenceId] FROM [NestedCollections] AS [n] @@ -2344,17 +1978,11 @@ SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [n].[Id], [n].[ParentReferenceId] FROM [NestedCollections] AS [n] @@ -2377,15 +2005,9 @@ 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 [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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]"); +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Nested_include_with_inheritance_collection_reference_split(bool async) @@ -2393,7 +2015,7 @@ public override async Task Nested_include_with_inheritance_collection_reference_ await base.Nested_include_with_inheritance_collection_reference_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -2402,16 +2024,10 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2420,17 +2036,11 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2439,17 +2049,11 @@ SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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], [t1].[Id0], [t1].[Name0], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator0] AS [Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[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], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2458,31 +2062,25 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN ( - 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] + SELECT [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t2].[Id] AS [Id0], [t2].[Name] AS [Name0], [t2].[ParentCollectionId], [t2].[ParentReferenceId], [t2].[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 [t2] + ) AS [t0] 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 [t2].[Id] = [t3].[ParentCollectionId] + ) AS [t2] ON [t0].[Id] = [t2].[ParentCollectionId] ) AS [t1] ON [t].[Id] = [t1].[BaseParentId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Nested_include_with_inheritance_collection_reference_reverse_split(bool async) @@ -2490,7 +2088,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], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o].[Id], [o].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[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], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedReferenceBase' AS [Discriminator] FROM [NestedReferences] AS [n] @@ -2513,16 +2111,10 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) 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], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [n].[Id], [n].[ParentCollectionId] FROM [NestedReferences] AS [n] @@ -2545,17 +2137,11 @@ SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [n].[Id], [n].[ParentCollectionId] FROM [NestedReferences] AS [n] @@ -2578,15 +2164,9 @@ 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 [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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]"); +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Nested_include_with_inheritance_collection_collection_split(bool async) @@ -2594,7 +2174,7 @@ public override async Task Nested_include_with_inheritance_collection_collection await base.Nested_include_with_inheritance_collection_collection_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -2603,16 +2183,10 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2621,17 +2195,11 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2640,17 +2208,11 @@ SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] 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] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [t0].[Id], [t0].[BaseParentId], [t0].[Name], [t0].[DerivedProperty], [t0].[Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2659,23 +2221,17 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN ( 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] ON [t].[Id] = [t1].[BaseParentId] -ORDER BY [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] +) AS [t0] ON [t].[Id] = [t0].[BaseParentId] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [t0].[Id]", + // + @"SELECT [t1].[Id], [t1].[Name], [t1].[ParentCollectionId], [t1].[ParentReferenceId], [t1].[Discriminator], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [t0].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2684,28 +2240,22 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN ( SELECT [b0].[Id], [b0].[BaseParentId] FROM [BaseCollectionsOnBase] AS [b0] UNION ALL SELECT [d1].[Id], [d1].[BaseParentId] FROM [DerivedCollectionsOnBase] AS [d1] -) AS [t1] ON [t].[Id] = [t1].[BaseParentId] +) AS [t0] ON [t].[Id] = [t0].[BaseParentId] INNER 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 [t2] ON [t1].[Id] = [t2].[ParentCollectionId] -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [t1].[Id]"); +) AS [t1] ON [t0].[Id] = [t1].[ParentCollectionId] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [t0].[Id]"); } public override async Task Nested_include_with_inheritance_collection_collection_reverse_split(bool async) @@ -2713,7 +2263,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], [t1].[Id], [t1].[Name], [t1].[BaseId], [t1].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id], [o].[Id], [o].[Name], [t2].[OwnedReferenceOnDerived_Id], [t2].[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], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], N'NestedCollectionBase' AS [Discriminator] FROM [NestedCollections] AS [n] @@ -2736,16 +2286,10 @@ UNION ALL FROM [DerivedEntities] AS [d1] ) 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], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [n].[Id], [n].[ParentCollectionId] FROM [NestedCollections] AS [n] @@ -2768,17 +2312,11 @@ SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] ) 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t1].[Id] = [o0].[BaseInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id] +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [n].[Id], [n].[ParentCollectionId] FROM [NestedCollections] AS [n] @@ -2801,15 +2339,9 @@ 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 [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 +LEFT JOIN [DerivedEntities] AS [d] ON [t1].[Id] = [d].[Id] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t1].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] -ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [t2].[Id]"); +ORDER BY [t].[Id], [t0].[Id], [t1].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override async Task Nested_include_collection_reference_on_non_entity_base_split(bool async) @@ -2869,7 +2401,7 @@ public override async Task Include_on_derived_type_with_queryable_Cast_split(boo await base.Include_on_derived_type_with_queryable_Cast_split(async); AssertSql( - @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id], [o].[Id], [o].[Name], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] + @"SELECT [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [o].[BaseInheritanceRelationshipEntityId], [d].[Id], [o].[Id], [o].[Name], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM ( SELECT [b].[Id], [b].[Name], NULL AS [BaseId], N'BaseInheritanceRelationshipEntity' AS [Discriminator] FROM [BaseEntities] AS [b] @@ -2878,17 +2410,11 @@ UNION ALL FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] WHERE [t].[Id] >= 4 -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [o0].[BaseInheritanceRelationshipEntityId], [o0].[Id], [o0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2897,18 +2423,12 @@ SELECT [d0].[Id] FROM [DerivedEntities] AS [d0] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [OwnedCollections] AS [o0] ON [t].[Id] = [o0].[BaseInheritanceRelationshipEntityId] WHERE [t].[Id] >= 4 -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2917,18 +2437,12 @@ SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [DerivedEntities_OwnedCollectionOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Id] >= 4 -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]", - // - @"SELECT [d0].[Id], [d0].[Name], [d0].[ParentId], [d0].[DerivedInheritanceRelationshipEntityId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id] +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]", + // + @"SELECT [d0].[Id], [d0].[Name], [d0].[ParentId], [d0].[DerivedInheritanceRelationshipEntityId], [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id] FROM ( SELECT [b].[Id] FROM [BaseEntities] AS [b] @@ -2937,16 +2451,10 @@ SELECT [d1].[Id] FROM [DerivedEntities] AS [d1] ) AS [t] 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 +LEFT JOIN [DerivedEntities] AS [d] ON [t].[Id] = [d].[Id] INNER JOIN [DerivedCollectionsOnDerived] AS [d0] ON [t].[Id] = [d0].[DerivedInheritanceRelationshipEntityId] WHERE [t].[Id] >= 4 -ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [t0].[Id]"); +ORDER BY [t].[Id], [o].[BaseInheritanceRelationshipEntityId], [d].[Id]"); } public override void Entity_can_make_separate_relationships_with_base_type_and_derived_type_both() diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPTRelationshipsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPTRelationshipsQuerySqlServerTest.cs index 037e62a7fd2..b22194a9873 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPTRelationshipsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTRelationshipsQuerySqlServerTest.cs @@ -65,12 +65,12 @@ 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], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], [d].[BaseId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b].[Id] AS [Id0], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id1], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id0], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] LEFT JOIN [DerivedEntities] AS [d] ON [b].[Id] = [d].[Id] ) AS [t] ON [c].[ParentId] = [t].[Id] @@ -101,12 +101,12 @@ 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], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], [d].[BaseId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b].[Id] AS [Id0], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id1], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id0], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] LEFT JOIN [DerivedEntities] AS [d] ON [b].[Id] = [d].[Id] ) AS [t] ON [c].[ParentId] = [t].[Id] @@ -203,11 +203,11 @@ public override async Task Include_collection_with_inheritance_on_derived_revers AssertSql( @"SELECT [b].[Id], [b].[Name], [b].[ParentId], [d].[DerivedInheritanceRelationshipEntityId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedCollectionOnDerived' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseCollectionsOnDerived] AS [b] LEFT JOIN [DerivedCollectionsOnDerived] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] INNER JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[ParentId] = [t].[Id] @@ -223,13 +223,13 @@ public override async Task Include_collection_with_inheritance_reverse(bool asyn AssertSql( @"SELECT [b].[Id], [b].[BaseParentId], [b].[Name], [d].[DerivedProperty], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedCollectionOnBase' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN [DerivedCollectionsOnBase] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[BaseParentId] = [t].[Id] @@ -268,13 +268,13 @@ public override async Task Include_collection_with_inheritance_with_filter_rever AssertSql( @"SELECT [b].[Id], [b].[BaseParentId], [b].[Name], [d].[DerivedProperty], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedCollectionOnBase' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN [DerivedCollectionsOnBase] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[BaseParentId] = [t].[Id] @@ -333,10 +333,10 @@ public override async Task Include_reference_without_inheritance_on_derived_reve await base.Include_reference_without_inheritance_on_derived_reverse(async); AssertSql( - @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [ReferencesOnDerived] AS [r] LEFT JOIN ( - SELECT [b].[Id], [b].[Name], [d].[BaseId], [b].[Id] AS [Id0], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id1], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + SELECT [b].[Id], [b].[Name], [d].[BaseId], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id0], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] INNER JOIN [DerivedEntities] AS [d] ON [b].[Id] = [d].[Id] ) AS [t] ON [r].[ParentId] = [t].[Id] @@ -350,12 +350,12 @@ 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], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [ReferencesOnBase] AS [r] LEFT JOIN ( SELECT [b].[Id], [b].[Name], [d].[BaseId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b].[Id] AS [Id0], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id1], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id0], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] LEFT JOIN [DerivedEntities] AS [d] ON [b].[Id] = [d].[Id] ) AS [t] ON [r].[ParentId] = [t].[Id] @@ -386,12 +386,12 @@ 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], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [r].[Id], [r].[Name], [r].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [ReferencesOnBase] AS [r] LEFT JOIN ( SELECT [b].[Id], [b].[Name], [d].[BaseId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b].[Id] AS [Id0], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id1], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id0], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] LEFT JOIN [DerivedEntities] AS [d] ON [b].[Id] = [d].[Id] ) AS [t] ON [r].[ParentId] = [t].[Id] @@ -488,11 +488,11 @@ public override async Task Include_reference_with_inheritance_on_derived_reverse AssertSql( @"SELECT [b].[Id], [b].[BaseParentId], [b].[Name], [d].[DerivedInheritanceRelationshipEntityId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedReferenceOnDerived' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseReferencesOnDerived] AS [b] LEFT JOIN [DerivedReferencesOnDerived] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] INNER JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[BaseParentId] = [t].[Id] @@ -569,11 +569,11 @@ public override async Task Include_reference_with_inheritance_on_derived_with_fi AssertSql( @"SELECT [b].[Id], [b].[BaseParentId], [b].[Name], [d].[DerivedInheritanceRelationshipEntityId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedReferenceOnDerived' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseReferencesOnDerived] AS [b] LEFT JOIN [DerivedReferencesOnDerived] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] INNER JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[BaseParentId] = [t].[Id] @@ -590,13 +590,13 @@ public override async Task Include_reference_with_inheritance_reverse(bool async AssertSql( @"SELECT [b].[Id], [b].[BaseParentId], [b].[Name], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedReferenceOnBase' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseReferencesOnBase] AS [b] LEFT JOIN [DerivedReferencesOnBase] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[BaseParentId] = [t].[Id] @@ -635,13 +635,13 @@ public override async Task Include_reference_with_inheritance_with_filter_revers AssertSql( @"SELECT [b].[Id], [b].[BaseParentId], [b].[Name], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedReferenceOnBase' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseReferencesOnBase] AS [b] LEFT JOIN [DerivedReferencesOnBase] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[BaseParentId] = [t].[Id] @@ -658,11 +658,11 @@ public override async Task Include_self_reference_with_inheritance(bool async) AssertSql( @"SELECT [b].[Id], [b].[Name], [d].[BaseId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' -END AS [Discriminator], [t].[Id], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[Name], [t].[BaseId], [b2].[BaseInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[Name], [t].[BaseId], [b2].[BaseInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] LEFT JOIN [DerivedEntities] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] INNER JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[Id] = [t].[BaseId] @@ -678,13 +678,13 @@ public override async Task Include_self_reference_with_inheritance_reverse(bool await base.Include_self_reference_with_inheritance_reverse(async); AssertSql( - @"SELECT [b].[Id], [b].[Name], [d].[BaseId], [t].[Id], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[Name], [t].[BaseId], [t].[Discriminator], [b2].[BaseInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [b].[Id], [b].[Name], [d].[BaseId], [t].[Id], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [d].[Id], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name], [t].[Name], [t].[BaseId], [t].[Discriminator], [b2].[BaseInheritanceRelationshipEntityId], [b2].[Id], [b2].[Name], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [d2].[DerivedInheritanceRelationshipEntityId], [d2].[Id], [d2].[Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] INNER JOIN [DerivedEntities] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [d].[BaseId] = [t].[Id] @@ -746,7 +746,7 @@ public override async Task Nested_include_with_inheritance_collection_collection AssertSql( @"SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], CASE WHEN [n0].[Id] IS NOT NULL THEN N'NestedCollectionDerived' -END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t0].[Id0], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[Id1], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[Id0], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [NestedCollections] AS [n] LEFT JOIN [NestedCollectionsDerived] AS [n0] ON [n].[Id] = [n0].[Id] LEFT JOIN ( @@ -759,7 +759,7 @@ FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] @@ -804,7 +804,7 @@ public override async Task Nested_include_with_inheritance_collection_reference_ AssertSql( @"SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], CASE WHEN [n0].[Id] IS NOT NULL THEN N'NestedReferenceDerived' -END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t0].[Id0], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[Id1], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[Id0], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [NestedReferences] AS [n] LEFT JOIN [NestedReferencesDerived] AS [n0] ON [n].[Id] = [n0].[Id] LEFT JOIN ( @@ -817,7 +817,7 @@ FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] @@ -889,7 +889,7 @@ public override async Task Nested_include_with_inheritance_reference_collection_ AssertSql( @"SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], CASE WHEN [n0].[Id] IS NOT NULL THEN N'NestedCollectionDerived' -END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t0].[Id0], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[Id1], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[Id0], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [NestedCollections] AS [n] LEFT JOIN [NestedCollectionsDerived] AS [n0] ON [n].[Id] = [n0].[Id] LEFT JOIN ( @@ -902,7 +902,7 @@ FROM [BaseReferencesOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] @@ -974,7 +974,7 @@ public override async Task Nested_include_with_inheritance_reference_reference_r AssertSql( @"SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], CASE WHEN [n0].[Id] IS NOT NULL THEN N'NestedReferenceDerived' -END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t0].[Id0], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[Id1], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [t0].[Id0], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [NestedReferences] AS [n] LEFT JOIN [NestedReferencesDerived] AS [n0] ON [n].[Id] = [n0].[Id] LEFT JOIN ( @@ -987,7 +987,7 @@ FROM [BaseReferencesOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] @@ -1075,19 +1075,19 @@ public override async Task Include_collection_with_inheritance_reverse_split(boo AssertSql( @"SELECT [b].[Id], [b].[BaseParentId], [b].[Name], [d].[DerivedProperty], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedCollectionOnBase' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN [DerivedCollectionsOnBase] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[BaseParentId] = [t].[Id] ORDER BY [b].[Id], [t].[Id]", - // - @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] + // + @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id] @@ -1095,8 +1095,8 @@ FROM [BaseEntities] AS [b0] ) AS [t] ON [b].[BaseParentId] = [t].[Id] INNER JOIN [BaseEntities_OwnedCollectionOnBase] AS [b1] ON [t].[Id] = [b1].[BaseInheritanceRelationshipEntityId] ORDER BY [b].[Id], [t].[Id]", - // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [b].[Id], [t].[Id] + // + @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [b].[Id], [t].[Id] FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id] @@ -1151,20 +1151,20 @@ public override async Task Include_collection_with_inheritance_with_filter_rever AssertSql( @"SELECT [b].[Id], [b].[BaseParentId], [b].[Name], [d].[DerivedProperty], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedCollectionOnBase' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN [DerivedCollectionsOnBase] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[BaseParentId] = [t].[Id] WHERE [b].[Name] <> N'Bar' OR [b].[Name] IS NULL ORDER BY [b].[Id], [t].[Id]", - // - @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] + // + @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id] @@ -1173,8 +1173,8 @@ FROM [BaseEntities] AS [b0] INNER JOIN [BaseEntities_OwnedCollectionOnBase] AS [b1] ON [t].[Id] = [b1].[BaseInheritanceRelationshipEntityId] WHERE [b].[Name] <> N'Bar' OR [b].[Name] IS NULL ORDER BY [b].[Id], [t].[Id]", - // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [b].[Id], [t].[Id] + // + @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [b].[Id], [t].[Id] FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id] @@ -1218,18 +1218,18 @@ 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], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], [d].[BaseId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b].[Id] AS [Id0], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id1], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id0], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] LEFT JOIN [DerivedEntities] AS [d] ON [b].[Id] = [d].[Id] ) AS [t] ON [c].[ParentId] = [t].[Id] ORDER BY [c].[Id], [t].[Id]", - // - @"SELECT [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [c].[Id], [t].[Id] + // + @"SELECT [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [c].[Id], [t].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] @@ -1237,8 +1237,8 @@ FROM [BaseEntities] AS [b] ) AS [t] ON [c].[ParentId] = [t].[Id] INNER JOIN [BaseEntities_OwnedCollectionOnBase] AS [b0] ON [t].[Id] = [b0].[BaseInheritanceRelationshipEntityId] ORDER BY [c].[Id], [t].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id] + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] @@ -1285,19 +1285,19 @@ 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], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] + @"SELECT [c].[Id], [c].[Name], [c].[ParentId], [t].[Id], [t].[Name], [t].[BaseId], [t].[Discriminator], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id], [b].[Name], [d].[BaseId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b].[Id] AS [Id0], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id1], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b].[OwnedReferenceOnBase_Id], [b].[OwnedReferenceOnBase_Name], [d].[Id] AS [Id0], [d].[OwnedReferenceOnDerived_Id], [d].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b] LEFT JOIN [DerivedEntities] AS [d] ON [b].[Id] = [d].[Id] ) AS [t] ON [c].[ParentId] = [t].[Id] WHERE [c].[Name] <> N'Bar' OR [c].[Name] IS NULL ORDER BY [c].[Id], [t].[Id]", - // - @"SELECT [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [c].[Id], [t].[Id] + // + @"SELECT [b0].[BaseInheritanceRelationshipEntityId], [b0].[Id], [b0].[Name], [c].[Id], [t].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] @@ -1306,8 +1306,8 @@ FROM [BaseEntities] AS [b] INNER JOIN [BaseEntities_OwnedCollectionOnBase] AS [b0] ON [t].[Id] = [b0].[BaseInheritanceRelationshipEntityId] WHERE [c].[Name] <> N'Bar' OR [c].[Name] IS NULL ORDER BY [c].[Id], [t].[Id]", - // - @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id] + // + @"SELECT [d0].[DerivedInheritanceRelationshipEntityId], [d0].[Id], [d0].[Name], [c].[Id], [t].[Id] FROM [CollectionsOnBase] AS [c] LEFT JOIN ( SELECT [b].[Id] @@ -1428,17 +1428,17 @@ public override async Task Include_collection_with_inheritance_on_derived_revers AssertSql( @"SELECT [b].[Id], [b].[Name], [b].[ParentId], [d].[DerivedInheritanceRelationshipEntityId], CASE WHEN [d].[Id] IS NOT NULL THEN N'DerivedCollectionOnDerived' -END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[Id0], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id1], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[Name], [t].[BaseId], [t].[OwnedReferenceOnBase_Id], [t].[OwnedReferenceOnBase_Name], [t].[Id0], [t].[OwnedReferenceOnDerived_Id], [t].[OwnedReferenceOnDerived_Name] FROM [BaseCollectionsOnDerived] AS [b] LEFT JOIN [DerivedCollectionsOnDerived] AS [d] ON [b].[Id] = [d].[Id] LEFT JOIN ( - SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] INNER JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t] ON [b].[ParentId] = [t].[Id] ORDER BY [b].[Id], [t].[Id]", - // - @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] + // + @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [b].[Id], [t].[Id] FROM [BaseCollectionsOnDerived] AS [b] LEFT JOIN ( SELECT [b0].[Id] @@ -1447,8 +1447,8 @@ FROM [BaseEntities] AS [b0] ) AS [t] ON [b].[ParentId] = [t].[Id] INNER JOIN [BaseEntities_OwnedCollectionOnBase] AS [b1] ON [t].[Id] = [b1].[BaseInheritanceRelationshipEntityId] ORDER BY [b].[Id], [t].[Id]", - // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [b].[Id], [t].[Id] + // + @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [b].[Id], [t].[Id] FROM [BaseCollectionsOnDerived] AS [b] LEFT JOIN ( SELECT [b0].[Id] @@ -1573,7 +1573,7 @@ public override async Task Nested_include_with_inheritance_reference_collection_ AssertSql( @"SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], CASE WHEN [n0].[Id] IS NOT NULL THEN N'NestedCollectionDerived' -END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [t0].[Id0], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [t0].[Id1], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [t0].[Id0], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [NestedCollections] AS [n] LEFT JOIN [NestedCollectionsDerived] AS [n0] ON [n].[Id] = [n0].[Id] LEFT JOIN ( @@ -1586,13 +1586,13 @@ FROM [BaseReferencesOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] ORDER BY [n].[Id], [t].[Id], [t0].[Id]", - // - @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [n].[Id], [t].[Id], [t0].[Id] + // + @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [n].[Id], [t].[Id], [t0].[Id] FROM [NestedCollections] AS [n] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] @@ -1604,8 +1604,8 @@ FROM [BaseEntities] AS [b0] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] INNER JOIN [BaseEntities_OwnedCollectionOnBase] AS [b1] ON [t0].[Id] = [b1].[BaseInheritanceRelationshipEntityId] ORDER BY [n].[Id], [t].[Id], [t0].[Id]", - // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [n].[Id], [t].[Id], [t0].[Id] + // + @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [n].[Id], [t].[Id], [t0].[Id] FROM [NestedCollections] AS [n] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] @@ -1667,7 +1667,7 @@ public override async Task Nested_include_with_inheritance_collection_reference_ AssertSql( @"SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], CASE WHEN [n0].[Id] IS NOT NULL THEN N'NestedReferenceDerived' -END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [t0].[Id0], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [t0].[Id1], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [t0].[Id0], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [NestedReferences] AS [n] LEFT JOIN [NestedReferencesDerived] AS [n0] ON [n].[Id] = [n0].[Id] LEFT JOIN ( @@ -1680,13 +1680,13 @@ FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] ORDER BY [n].[Id], [t].[Id], [t0].[Id]", - // - @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [n].[Id], [t].[Id], [t0].[Id] + // + @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [n].[Id], [t].[Id], [t0].[Id] FROM [NestedReferences] AS [n] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] @@ -1698,8 +1698,8 @@ FROM [BaseEntities] AS [b0] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] INNER JOIN [BaseEntities_OwnedCollectionOnBase] AS [b1] ON [t0].[Id] = [b1].[BaseInheritanceRelationshipEntityId] ORDER BY [n].[Id], [t].[Id], [t0].[Id]", - // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [n].[Id], [t].[Id], [t0].[Id] + // + @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [n].[Id], [t].[Id], [t0].[Id] FROM [NestedReferences] AS [n] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] @@ -1769,7 +1769,7 @@ public override async Task Nested_include_with_inheritance_collection_collection AssertSql( @"SELECT [n].[Id], [n].[Name], [n].[ParentCollectionId], [n].[ParentReferenceId], CASE WHEN [n0].[Id] IS NOT NULL THEN N'NestedCollectionDerived' -END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [t0].[Id0], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [t0].[Id1], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] +END AS [Discriminator], [t].[Id], [t].[BaseParentId], [t].[Name], [t].[DerivedProperty], [t].[Discriminator], [t0].[Id], [t0].[Name], [t0].[BaseId], [t0].[Discriminator], [t0].[OwnedReferenceOnBase_Id], [t0].[OwnedReferenceOnBase_Name], [t0].[Id0], [t0].[OwnedReferenceOnDerived_Id], [t0].[OwnedReferenceOnDerived_Name] FROM [NestedCollections] AS [n] LEFT JOIN [NestedCollectionsDerived] AS [n0] ON [n].[Id] = [n0].[Id] LEFT JOIN ( @@ -1782,13 +1782,13 @@ FROM [BaseCollectionsOnBase] AS [b] LEFT JOIN ( SELECT [b0].[Id], [b0].[Name], [d0].[BaseId], CASE WHEN [d0].[Id] IS NOT NULL THEN N'DerivedInheritanceRelationshipEntity' - END AS [Discriminator], [b0].[Id] AS [Id0], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id1], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] + END AS [Discriminator], [b0].[OwnedReferenceOnBase_Id], [b0].[OwnedReferenceOnBase_Name], [d0].[Id] AS [Id0], [d0].[OwnedReferenceOnDerived_Id], [d0].[OwnedReferenceOnDerived_Name] FROM [BaseEntities] AS [b0] LEFT JOIN [DerivedEntities] AS [d0] ON [b0].[Id] = [d0].[Id] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] ORDER BY [n].[Id], [t].[Id], [t0].[Id]", - // - @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [n].[Id], [t].[Id], [t0].[Id] + // + @"SELECT [b1].[BaseInheritanceRelationshipEntityId], [b1].[Id], [b1].[Name], [n].[Id], [t].[Id], [t0].[Id] FROM [NestedCollections] AS [n] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] @@ -1800,8 +1800,8 @@ FROM [BaseEntities] AS [b0] ) AS [t0] ON [t].[BaseParentId] = [t0].[Id] INNER JOIN [BaseEntities_OwnedCollectionOnBase] AS [b1] ON [t0].[Id] = [b1].[BaseInheritanceRelationshipEntityId] ORDER BY [n].[Id], [t].[Id], [t0].[Id]", - // - @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [n].[Id], [t].[Id], [t0].[Id] + // + @"SELECT [d1].[DerivedInheritanceRelationshipEntityId], [d1].[Id], [d1].[Name], [n].[Id], [t].[Id], [t0].[Id] FROM [NestedCollections] AS [n] LEFT JOIN ( SELECT [b].[Id], [b].[BaseParentId] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalOwnedQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalOwnedQuerySqlServerTest.cs index 7e620263cd7..472999259ea 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalOwnedQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalOwnedQuerySqlServerTest.cs @@ -866,13 +866,13 @@ public override async Task Query_for_base_type_loads_all_owned_navs_split(bool a @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PeriodEnd], [o].[PeriodStart], [o].[PersonAddress_AddressLine], [o].[PeriodEnd], [o].[PeriodStart], [o].[PersonAddress_PlaceType], [o].[PersonAddress_ZipCode], [o].[PersonAddress_Country_Name], [o].[PersonAddress_Country_PlanetId], [o].[BranchAddress_BranchName], [o].[BranchAddress_PlaceType], [o].[BranchAddress_Country_Name], [o].[BranchAddress_Country_PlanetId], [o].[LeafBAddress_LeafBType], [o].[LeafBAddress_PlaceType], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] ORDER BY [o].[Id]", - // - @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] + // + @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]", - // - @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] + // + @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] INNER JOIN [OrderDetail] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o1] ON [o0].[ClientId] = [o1].[OrderClientId] AND [o0].[Id] = [o1].[OrderId] @@ -888,14 +888,14 @@ public override async Task Query_for_branch_type_loads_all_owned_navs_split(bool FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] WHERE [o].[Discriminator] IN (N'Branch', N'LeafA') ORDER BY [o].[Id]", - // - @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] + // + @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Discriminator] IN (N'Branch', N'LeafA') ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]", - // - @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] + // + @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] INNER JOIN [OrderDetail] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o1] ON [o0].[ClientId] = [o1].[OrderClientId] AND [o0].[Id] = [o1].[OrderId] @@ -916,8 +916,8 @@ SELECT TOP(@__p_0) [t].[Id], [t].[Discriminator], [t].[Name], [t].[PeriodEnd], [ FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] ) AS [t] ORDER BY [t].[Id]", - // - @"@__p_0='5' + // + @"@__p_0='5' SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [t0].[Id] FROM ( @@ -930,8 +930,8 @@ ORDER BY [t].[Id] ) AS [t0] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [t0].[Id] = [o0].[ClientId] ORDER BY [t0].[Id], [o0].[ClientId], [o0].[Id]", - // - @"@__p_0='5' + // + @"@__p_0='5' SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [t0].[Id], [o0].[ClientId], [o0].[Id] FROM ( @@ -997,14 +997,14 @@ public override async Task Query_with_OfType_eagerly_loads_correct_owned_navigat FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] WHERE [o].[Discriminator] = N'LeafA' ORDER BY [o].[Id]", - // - @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] + // + @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Discriminator] = N'LeafA' ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]", - // - @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] + // + @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] INNER JOIN [OrderDetail] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o1] ON [o0].[ClientId] = [o1].[OrderClientId] AND [o0].[Id] = [o1].[OrderId] @@ -1021,14 +1021,14 @@ public override async Task Unmapped_property_projection_loads_owned_navigations_ FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] WHERE [o].[Id] = 1 ORDER BY [o].[Id]", - // - @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] + // + @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Id] = 1 ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]", - // - @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] + // + @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] INNER JOIN [OrderDetail] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o1] ON [o0].[ClientId] = [o1].[OrderClientId] AND [o0].[Id] = [o1].[OrderId] @@ -1045,14 +1045,14 @@ public override async Task Can_query_on_indexer_properties_split(bool async) FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] WHERE [o].[Name] = N'Mona Cy' ORDER BY [o].[Id]", - // - @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] + // + @"SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o0].[PeriodEnd], [o0].[PeriodStart], [o].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Name] = N'Mona Cy' ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]", - // - @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] + // + @"SELECT [o1].[OrderClientId], [o1].[OrderId], [o1].[Id], [o1].[Detail], [o1].[PeriodEnd], [o1].[PeriodStart], [o].[Id], [o0].[ClientId], [o0].[Id] FROM [OwnedPerson] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o] INNER JOIN [Order] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o0] ON [o].[Id] = [o0].[ClientId] INNER JOIN [OrderDetail] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [o1] ON [o0].[ClientId] = [o1].[OrderClientId] AND [o0].[Id] = [o1].[OrderId] @@ -1117,44 +1117,20 @@ public override async Task Using_from_sql_on_owner_generates_join_with_table_for await base.Using_from_sql_on_owner_generates_join_with_table_for_owned_shared_dependents(async); AssertSql( - @"SELECT [m].[Id], [m].[Discriminator], [m].[Name], [m].[PeriodEnd], [m].[PeriodStart], [t].[Id], [t0].[Id], [t1].[Id], [t2].[Id], [t3].[ClientId], [t3].[Id], [t3].[OrderDate], [t3].[PeriodEnd], [t3].[PeriodStart], [t3].[OrderClientId], [t3].[OrderId], [t3].[Id0], [t3].[Detail], [t3].[PeriodEnd0], [t3].[PeriodStart0], [t].[PersonAddress_AddressLine], [t].[PeriodEnd], [t].[PeriodStart], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[Id0], [t].[PersonAddress_Country_Name], [t].[PeriodEnd0], [t].[PeriodStart0], [t].[PersonAddress_Country_PlanetId], [t0].[BranchAddress_BranchName], [t0].[PeriodEnd], [t0].[PeriodStart], [t0].[BranchAddress_PlaceType], [t0].[Id0], [t0].[BranchAddress_Country_Name], [t0].[PeriodEnd0], [t0].[PeriodStart0], [t0].[BranchAddress_Country_PlanetId], [t1].[LeafBAddress_LeafBType], [t1].[PeriodEnd], [t1].[PeriodStart], [t1].[LeafBAddress_PlaceType], [t1].[Id0], [t1].[LeafBAddress_Country_Name], [t1].[PeriodEnd0], [t1].[PeriodStart0], [t1].[LeafBAddress_Country_PlanetId], [t2].[LeafAAddress_LeafType], [t2].[PeriodEnd], [t2].[PeriodStart], [t2].[LeafAAddress_PlaceType], [t2].[Id0], [t2].[LeafAAddress_Country_Name], [t2].[PeriodEnd0], [t2].[PeriodStart0], [t2].[LeafAAddress_Country_PlanetId] + @"SELECT [m].[Id], [m].[Discriminator], [m].[Name], [m].[PeriodEnd], [m].[PeriodStart], [o].[Id], [o0].[Id], [o1].[Id], [o2].[Id], [t].[ClientId], [t].[Id], [t].[OrderDate], [t].[PeriodEnd], [t].[PeriodStart], [t].[OrderClientId], [t].[OrderId], [t].[Id0], [t].[Detail], [t].[PeriodEnd0], [t].[PeriodStart0], [o].[PersonAddress_AddressLine], [o].[PeriodEnd], [o].[PeriodStart], [o].[PersonAddress_PlaceType], [o].[PersonAddress_ZipCode], [o].[PersonAddress_Country_Name], [o].[PersonAddress_Country_PlanetId], [o0].[BranchAddress_BranchName], [o0].[PeriodEnd], [o0].[PeriodStart], [o0].[BranchAddress_PlaceType], [o0].[BranchAddress_Country_Name], [o0].[BranchAddress_Country_PlanetId], [o1].[LeafBAddress_LeafBType], [o1].[PeriodEnd], [o1].[PeriodStart], [o1].[LeafBAddress_PlaceType], [o1].[LeafBAddress_Country_Name], [o1].[LeafBAddress_Country_PlanetId], [o2].[LeafAAddress_LeafType], [o2].[PeriodEnd], [o2].[PeriodStart], [o2].[LeafAAddress_PlaceType], [o2].[LeafAAddress_Country_Name], [o2].[LeafAAddress_Country_PlanetId] FROM ( SELECT * FROM ""OwnedPerson"" ) AS [m] -LEFT JOIN ( - SELECT [o].[Id], [o].[PersonAddress_AddressLine], [o].[PeriodEnd], [o].[PeriodStart], [o].[PersonAddress_PlaceType], [o].[PersonAddress_ZipCode], [o].[Id] AS [Id0], [o].[PersonAddress_Country_Name], [o].[PeriodEnd] AS [PeriodEnd0], [o].[PeriodStart] AS [PeriodStart0], [o].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o] - WHERE [o].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [m].[Id] = CASE - WHEN [t].[PersonAddress_ZipCode] IS NOT NULL THEN [t].[Id] -END -LEFT JOIN ( - SELECT [o0].[Id], [o0].[BranchAddress_BranchName], [o0].[PeriodEnd], [o0].[PeriodStart], [o0].[BranchAddress_PlaceType], [o0].[Id] AS [Id0], [o0].[BranchAddress_Country_Name], [o0].[PeriodEnd] AS [PeriodEnd0], [o0].[PeriodStart] AS [PeriodStart0], [o0].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[BranchAddress_BranchName] IS NOT NULL -) AS [t0] ON [m].[Id] = CASE - WHEN [t0].[BranchAddress_BranchName] IS NOT NULL THEN [t0].[Id] -END -LEFT JOIN ( - SELECT [o1].[Id], [o1].[LeafBAddress_LeafBType], [o1].[PeriodEnd], [o1].[PeriodStart], [o1].[LeafBAddress_PlaceType], [o1].[Id] AS [Id0], [o1].[LeafBAddress_Country_Name], [o1].[PeriodEnd] AS [PeriodEnd0], [o1].[PeriodStart] AS [PeriodStart0], [o1].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[LeafBAddress_LeafBType] IS NOT NULL -) AS [t1] ON [m].[Id] = CASE - WHEN [t1].[LeafBAddress_LeafBType] IS NOT NULL THEN [t1].[Id] -END -LEFT JOIN ( - SELECT [o2].[Id], [o2].[LeafAAddress_LeafType], [o2].[PeriodEnd], [o2].[PeriodStart], [o2].[LeafAAddress_PlaceType], [o2].[Id] AS [Id0], [o2].[LeafAAddress_Country_Name], [o2].[PeriodEnd] AS [PeriodEnd0], [o2].[PeriodStart] AS [PeriodStart0], [o2].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[LeafAAddress_LeafType] IS NOT NULL -) AS [t2] ON [m].[Id] = CASE - WHEN [t2].[LeafAAddress_LeafType] IS NOT NULL THEN [t2].[Id] -END +LEFT JOIN [OwnedPerson] AS [o] ON [m].[Id] = [o].[Id] +LEFT JOIN [OwnedPerson] AS [o0] ON [m].[Id] = [o0].[Id] +LEFT JOIN [OwnedPerson] AS [o1] ON [m].[Id] = [o1].[Id] +LEFT JOIN [OwnedPerson] AS [o2] ON [m].[Id] = [o2].[Id] LEFT JOIN ( SELECT [o3].[ClientId], [o3].[Id], [o3].[OrderDate], [o3].[PeriodEnd], [o3].[PeriodStart], [o4].[OrderClientId], [o4].[OrderId], [o4].[Id] AS [Id0], [o4].[Detail], [o4].[PeriodEnd] AS [PeriodEnd0], [o4].[PeriodStart] AS [PeriodStart0] FROM [Order] AS [o3] LEFT JOIN [OrderDetail] AS [o4] ON [o3].[ClientId] = [o4].[OrderClientId] AND [o3].[Id] = [o4].[OrderId] -) AS [t3] ON [m].[Id] = [t3].[ClientId] -ORDER BY [m].[Id], [t].[Id], [t0].[Id], [t1].[Id], [t2].[Id], [t3].[ClientId], [t3].[Id], [t3].[OrderClientId], [t3].[OrderId]"); +) AS [t] ON [m].[Id] = [t].[ClientId] +ORDER BY [m].[Id], [o].[Id], [o0].[Id], [o1].[Id], [o2].[Id], [t].[ClientId], [t].[Id], [t].[OrderClientId], [t].[OrderId]"); } public override async Task Projecting_collection_correlated_with_keyless_entity_after_navigation_works_using_parent_identifiers( diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalTableSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalTableSqlServerTest.cs index 0fc5b92ccae..ffc240af576 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalTableSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalTableSqlServerTest.cs @@ -140,17 +140,13 @@ public virtual async Task Temporal_owned_subquery(bool async) AssertSql( @"@__p_0='3' -SELECT [t0].[Id], [t0].[Description], [t0].[EndTime], [t0].[StartTime], [o].[MainEntityDifferentTableId], [o].[Description], [o].[EndTime], [o].[StartTime] +SELECT TOP(@__p_0) [t].[Id], [t].[Description], [t].[EndTime], [t].[StartTime], [t].[MainEntityDifferentTableId], [t].[Description0], [t].[EndTime0], [t].[StartTime0] FROM ( - SELECT TOP(@__p_0) [t].[Id], [t].[Description], [t].[EndTime], [t].[StartTime] - FROM ( - SELECT DISTINCT [m].[Id], [m].[Description], [m].[EndTime], [m].[StartTime] - FROM [MainEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [m] - ) AS [t] - ORDER BY [t].[Id] DESC -) AS [t0] -LEFT JOIN [OwnedEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [o] ON [t0].[Id] = [o].[MainEntityDifferentTableId] -ORDER BY [t0].[Id] DESC"); + SELECT DISTINCT [m].[Id], [m].[Description], [m].[EndTime], [m].[StartTime], [o].[MainEntityDifferentTableId], [o].[Description] AS [Description0], [o].[EndTime] AS [EndTime0], [o].[StartTime] AS [StartTime0] + FROM [MainEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [m] + LEFT JOIN [OwnedEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [o] ON [m].[Id] = [o].[MainEntityDifferentTableId] +) AS [t] +ORDER BY [t].[Id] DESC"); } [ConditionalTheory] @@ -173,19 +169,19 @@ public virtual async Task Temporal_owned_complex(bool async) AssertSql( @"@__p_0='3' -SELECT [t0].[Id], [t0].[Description], [t0].[EndTime], [t0].[StartTime], [o].[MainEntityDifferentTableId], [o].[Description], [o].[EndTime], [o].[StartTime], [t0].[Id0], [t0].[Description0], [t0].[EndTime0], [t0].[StartTime0], [o0].[MainEntityDifferentTableId], [o0].[Description], [o0].[EndTime], [o0].[StartTime], [m1].[Id], [m1].[Description], [m1].[EndTime], [m1].[StartTime], [o1].[MainEntityDifferentTableId], [o1].[Description], [o1].[EndTime], [o1].[StartTime] +SELECT [t0].[Id], [t0].[Description], [t0].[EndTime], [t0].[StartTime], [t0].[MainEntityDifferentTableId], [t0].[Description1], [t0].[EndTime1], [t0].[StartTime1], [t0].[Id0], [t0].[Description0], [t0].[EndTime0], [t0].[StartTime0], [t0].[MainEntityDifferentTableId0], [t0].[Description2], [t0].[EndTime2], [t0].[StartTime2], [m1].[Id], [m1].[Description], [m1].[EndTime], [m1].[StartTime], [o1].[MainEntityDifferentTableId], [o1].[Description], [o1].[EndTime], [o1].[StartTime] FROM ( - SELECT TOP(@__p_0) [t].[Id], [t].[Description], [t].[EndTime], [t].[StartTime], [t].[Id0], [t].[Description0], [t].[EndTime0], [t].[StartTime0] + SELECT TOP(@__p_0) [t].[Id], [t].[Description], [t].[EndTime], [t].[StartTime], [t].[Id0], [t].[Description0], [t].[EndTime0], [t].[StartTime0], [t].[MainEntityDifferentTableId], [t].[Description1], [t].[EndTime1], [t].[StartTime1], [t].[MainEntityDifferentTableId0], [t].[Description2], [t].[EndTime2], [t].[StartTime2] FROM ( - SELECT DISTINCT [m].[Id], [m].[Description], [m].[EndTime], [m].[StartTime], [m0].[Id] AS [Id0], [m0].[Description] AS [Description0], [m0].[EndTime] AS [EndTime0], [m0].[StartTime] AS [StartTime0] + SELECT DISTINCT [m].[Id], [m].[Description], [m].[EndTime], [m].[StartTime], [m0].[Id] AS [Id0], [m0].[Description] AS [Description0], [m0].[EndTime] AS [EndTime0], [m0].[StartTime] AS [StartTime0], [o].[MainEntityDifferentTableId], [o].[Description] AS [Description1], [o].[EndTime] AS [EndTime1], [o].[StartTime] AS [StartTime1], [o0].[MainEntityDifferentTableId] AS [MainEntityDifferentTableId0], [o0].[Description] AS [Description2], [o0].[EndTime] AS [EndTime2], [o0].[StartTime] AS [StartTime2] FROM [MainEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [m] INNER JOIN [MainEntityDifferentTable] AS [m0] ON [m].[Id] = [m0].[Id] + LEFT JOIN [OwnedEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [o] ON [m].[Id] = [o].[MainEntityDifferentTableId] + LEFT JOIN [OwnedEntityDifferentTable] AS [o0] ON [m0].[Id] = [o0].[MainEntityDifferentTableId] ) AS [t] ORDER BY [t].[Id] DESC ) AS [t0] INNER JOIN [MainEntityDifferentTable] AS [m1] ON [t0].[Id] = [m1].[Id] -LEFT JOIN [OwnedEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [o] ON [t0].[Id] = [o].[MainEntityDifferentTableId] -LEFT JOIN [OwnedEntityDifferentTable] AS [o0] ON [t0].[Id0] = [o0].[MainEntityDifferentTableId] LEFT JOIN [OwnedEntityDifferentTable] AS [o1] ON [m1].[Id] = [o1].[MainEntityDifferentTableId] ORDER BY [t0].[Id] DESC"); } @@ -210,19 +206,19 @@ public virtual async Task Temporal_owned_complex_with_nontrivial_alias(bool asyn AssertSql( @"@__p_0='3' -SELECT [t0].[Id], [t0].[Description], [t0].[EndTime], [t0].[StartTime], [o].[MainEntityDifferentTableId], [o].[Description], [o].[EndTime], [o].[StartTime], [t0].[Id0], [t0].[Description0], [t0].[EndTime0], [t0].[StartTime0], [o0].[MainEntityDifferentTableId], [o0].[Description], [o0].[EndTime], [o0].[StartTime], [m1].[Id], [m1].[Description], [m1].[EndTime], [m1].[StartTime], [o1].[MainEntityDifferentTableId], [o1].[Description], [o1].[EndTime], [o1].[StartTime] +SELECT [t0].[Id], [t0].[Description], [t0].[EndTime], [t0].[StartTime], [t0].[MainEntityDifferentTableId], [t0].[Description1], [t0].[EndTime1], [t0].[StartTime1], [t0].[Id0], [t0].[Description0], [t0].[EndTime0], [t0].[StartTime0], [t0].[MainEntityDifferentTableId0], [t0].[Description2], [t0].[EndTime2], [t0].[StartTime2], [m1].[Id], [m1].[Description], [m1].[EndTime], [m1].[StartTime], [o1].[MainEntityDifferentTableId], [o1].[Description], [o1].[EndTime], [o1].[StartTime] FROM ( - SELECT TOP(@__p_0) [t].[Id], [t].[Description], [t].[EndTime], [t].[StartTime], [t].[Id0], [t].[Description0], [t].[EndTime0], [t].[StartTime0] + SELECT TOP(@__p_0) [t].[Id], [t].[Description], [t].[EndTime], [t].[StartTime], [t].[Id0], [t].[Description0], [t].[EndTime0], [t].[StartTime0], [t].[MainEntityDifferentTableId], [t].[Description1], [t].[EndTime1], [t].[StartTime1], [t].[MainEntityDifferentTableId0], [t].[Description2], [t].[EndTime2], [t].[StartTime2] FROM ( - SELECT DISTINCT [m].[Id], [m].[Description], [m].[EndTime], [m].[StartTime], [m0].[Id] AS [Id0], [m0].[Description] AS [Description0], [m0].[EndTime] AS [EndTime0], [m0].[StartTime] AS [StartTime0] + SELECT DISTINCT [m].[Id], [m].[Description], [m].[EndTime], [m].[StartTime], [m0].[Id] AS [Id0], [m0].[Description] AS [Description0], [m0].[EndTime] AS [EndTime0], [m0].[StartTime] AS [StartTime0], [o].[MainEntityDifferentTableId], [o].[Description] AS [Description1], [o].[EndTime] AS [EndTime1], [o].[StartTime] AS [StartTime1], [o0].[MainEntityDifferentTableId] AS [MainEntityDifferentTableId0], [o0].[Description] AS [Description2], [o0].[EndTime] AS [EndTime2], [o0].[StartTime] AS [StartTime2] FROM [MainEntityDifferentTable] AS [m] INNER JOIN [MainEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [m0] ON [m].[Id] = [m0].[Id] + LEFT JOIN [OwnedEntityDifferentTable] AS [o] ON [m].[Id] = [o].[MainEntityDifferentTableId] + LEFT JOIN [OwnedEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [o0] ON [m0].[Id] = [o0].[MainEntityDifferentTableId] ) AS [t] ORDER BY [t].[Id] DESC ) AS [t0] INNER JOIN [MainEntityDifferentTable] AS [m1] ON [t0].[Id] = [m1].[Id] -LEFT JOIN [OwnedEntityDifferentTable] AS [o] ON [t0].[Id] = [o].[MainEntityDifferentTableId] -LEFT JOIN [OwnedEntityDifferentTable] FOR SYSTEM_TIME AS OF '2000-01-01T00:00:00.0000000' AS [o0] ON [t0].[Id0] = [o0].[MainEntityDifferentTableId] LEFT JOIN [OwnedEntityDifferentTable] AS [o1] ON [m1].[Id] = [o1].[MainEntityDifferentTableId] ORDER BY [t0].[Id] DESC"); } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/EntitySplittingQuerySqliteFixture.cs b/test/EFCore.Sqlite.FunctionalTests/Query/EntitySplittingQuerySqliteFixture.cs deleted file mode 100644 index 0b81029afbc..00000000000 --- a/test/EFCore.Sqlite.FunctionalTests/Query/EntitySplittingQuerySqliteFixture.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.EntityFrameworkCore.Query; - -public class EntitySplittingQuerySqliteFixture : EntitySplittingQueryFixtureBase -{ - protected override ITestStoreFactory TestStoreFactory - => SqliteTestStoreFactory.Instance; -} diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/EntitySplittingQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/EntitySplittingQuerySqliteTest.cs index 7292d06b522..0ffd39b6493 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/EntitySplittingQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/EntitySplittingQuerySqliteTest.cs @@ -3,15 +3,355 @@ namespace Microsoft.EntityFrameworkCore.Query; -public class EntitySplittingQuerySqliteTest : EntitySplittingQueryTestBase +public class EntitySplittingQuerySqliteTest : EntitySplittingQueryTestBase { - public EntitySplittingQuerySqliteTest(EntitySplittingQuerySqliteFixture fixture, ITestOutputHelper testOutputHelper) - : base(fixture) + public EntitySplittingQuerySqliteTest() { - Fixture.TestSqlLoggerFactory.Clear(); - //Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper); } - private void AssertSql(params string[] expected) - => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); + protected override ITestStoreFactory TestStoreFactory => SqliteTestStoreFactory.Instance; + + public override async Task Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing(bool async) + { + await base.Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing(async); + + AssertSql( + @"SELECT ""e"".""Id"", ""e"".""EntityThreeId"", ""e"".""IntValue1"", ""e"".""IntValue2"", ""e"".""IntValue3"", ""e"".""IntValue4"", ""e"".""StringValue1"", ""e"".""StringValue2"", ""e"".""StringValue3"", ""e"".""StringValue4"", ""o"".""EntityOneId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" +FROM ""EntityOnes"" AS ""e"" +LEFT JOIN ""OwnedReferences"" AS ""o"" ON ""e"".""Id"" = ""o"".""EntityOneId"" +LEFT JOIN ""OwnedReferenceExtras2"" AS ""o0"" ON ""o"".""EntityOneId"" = ""o0"".""EntityOneId"" +LEFT JOIN ""OwnedReferenceExtras1"" AS ""o1"" ON ""o"".""EntityOneId"" = ""o1"".""EntityOneId"""); + } + + public override async Task Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing_custom_projection(bool async) + { + await base.Normal_entity_owning_a_split_reference_with_main_fragment_not_sharing_custom_projection(async); + + AssertSql( + @"SELECT ""e"".""Id"", ""o0"".""OwnedIntValue4"", ""o0"".""OwnedStringValue4"" +FROM ""EntityOnes"" AS ""e"" +LEFT JOIN ""OwnedReferences"" AS ""o"" ON ""e"".""Id"" = ""o"".""EntityOneId"" +LEFT JOIN ""OwnedReferenceExtras2"" AS ""o0"" ON ""o"".""EntityOneId"" = ""o0"".""EntityOneId"""); + } + + public override async Task Normal_entity_owning_a_split_collection(bool async) + { + await base.Normal_entity_owning_a_split_collection(async); + + AssertSql( + @"SELECT ""e"".""Id"", ""e"".""EntityThreeId"", ""e"".""IntValue1"", ""e"".""IntValue2"", ""e"".""IntValue3"", ""e"".""IntValue4"", ""e"".""StringValue1"", ""e"".""StringValue2"", ""e"".""StringValue3"", ""e"".""StringValue4"", ""t"".""EntityOneId"", ""t"".""Id"", ""t"".""OwnedIntValue1"", ""t"".""OwnedIntValue2"", ""t"".""OwnedIntValue3"", ""t"".""OwnedIntValue4"", ""t"".""OwnedStringValue1"", ""t"".""OwnedStringValue2"", ""t"".""OwnedStringValue3"", ""t"".""OwnedStringValue4"" +FROM ""EntityOnes"" AS ""e"" +LEFT JOIN ( + SELECT ""o"".""EntityOneId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" + FROM ""OwnedCollection"" AS ""o"" + INNER JOIN ""OwnedCollectionExtras2"" AS ""o0"" ON ""o"".""EntityOneId"" = ""o0"".""EntityOneId"" AND ""o"".""Id"" = ""o0"".""Id"" + INNER JOIN ""OwnedCollectionExtras1"" AS ""o1"" ON ""o"".""EntityOneId"" = ""o1"".""EntityOneId"" AND ""o"".""Id"" = ""o1"".""Id"" +) AS ""t"" ON ""e"".""Id"" = ""t"".""EntityOneId"" +ORDER BY ""e"".""Id"", ""t"".""EntityOneId"""); + } + + public override async Task Split_entity_owning_a_split_reference_without_table_sharing(bool async) + { + await base.Split_entity_owning_a_split_reference_without_table_sharing(async); + + AssertSql( + @"SELECT ""e"".""Id"", ""e"".""EntityThreeId"", ""e"".""IntValue1"", ""e"".""IntValue2"", ""s0"".""IntValue3"", ""s"".""IntValue4"", ""e"".""StringValue1"", ""e"".""StringValue2"", ""s0"".""StringValue3"", ""s"".""StringValue4"", ""o"".""EntityOneId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" +FROM ""EntityOne"" AS ""e"" +INNER JOIN ""SplitEntityOnePart3"" AS ""s"" ON ""e"".""Id"" = ""s"".""Id"" +INNER JOIN ""SplitEntityOnePart2"" AS ""s0"" ON ""e"".""Id"" = ""s0"".""Id"" +LEFT JOIN ""OwnedReferences"" AS ""o"" ON ""e"".""Id"" = ""o"".""EntityOneId"" +LEFT JOIN ""OwnedReferenceExtras2"" AS ""o0"" ON ""o"".""EntityOneId"" = ""o0"".""EntityOneId"" +LEFT JOIN ""OwnedReferenceExtras1"" AS ""o1"" ON ""o"".""EntityOneId"" = ""o1"".""EntityOneId"""); + } + + public override async Task Split_entity_owning_a_split_collection(bool async) + { + await base.Split_entity_owning_a_split_collection(async); + + AssertSql( + @"SELECT ""e"".""Id"", ""e"".""EntityThreeId"", ""e"".""IntValue1"", ""e"".""IntValue2"", ""s0"".""IntValue3"", ""s"".""IntValue4"", ""e"".""StringValue1"", ""e"".""StringValue2"", ""s0"".""StringValue3"", ""s"".""StringValue4"", ""t"".""EntityOneId"", ""t"".""Id"", ""t"".""OwnedIntValue1"", ""t"".""OwnedIntValue2"", ""t"".""OwnedIntValue3"", ""t"".""OwnedIntValue4"", ""t"".""OwnedStringValue1"", ""t"".""OwnedStringValue2"", ""t"".""OwnedStringValue3"", ""t"".""OwnedStringValue4"" +FROM ""EntityOne"" AS ""e"" +INNER JOIN ""SplitEntityOnePart3"" AS ""s"" ON ""e"".""Id"" = ""s"".""Id"" +INNER JOIN ""SplitEntityOnePart2"" AS ""s0"" ON ""e"".""Id"" = ""s0"".""Id"" +LEFT JOIN ( + SELECT ""o"".""EntityOneId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" + FROM ""OwnedCollection"" AS ""o"" + INNER JOIN ""OwnedCollectionExtras2"" AS ""o0"" ON ""o"".""EntityOneId"" = ""o0"".""EntityOneId"" AND ""o"".""Id"" = ""o0"".""Id"" + INNER JOIN ""OwnedCollectionExtras1"" AS ""o1"" ON ""o"".""EntityOneId"" = ""o1"".""EntityOneId"" AND ""o"".""Id"" = ""o1"".""Id"" +) AS ""t"" ON ""e"".""Id"" = ""t"".""EntityOneId"" +ORDER BY ""e"".""Id"", ""t"".""EntityOneId"""); + } + public override async Task Split_entity_owning_a_split_reference_with_table_sharing_6(bool async) + { + await base.Split_entity_owning_a_split_reference_with_table_sharing_6(async); + + AssertSql( + @"SELECT ""s"".""Id"", ""s"".""EntityThreeId"", ""s"".""IntValue1"", ""s"".""IntValue2"", ""s1"".""IntValue3"", ""s0"".""IntValue4"", ""s"".""StringValue1"", ""s"".""StringValue2"", ""s1"".""StringValue3"", ""s0"".""StringValue4"", ""s1"".""Id"", ""s1"".""OwnedReference_Id"", ""s1"".""OwnedReference_OwnedIntValue1"", ""s1"".""OwnedReference_OwnedIntValue2"", ""s0"".""OwnedReference_OwnedIntValue3"", ""o"".""OwnedIntValue4"", ""s1"".""OwnedReference_OwnedStringValue1"", ""s1"".""OwnedReference_OwnedStringValue2"", ""s0"".""OwnedReference_OwnedStringValue3"", ""o"".""OwnedStringValue4"" +FROM ""SplitEntityOnePart1"" AS ""s"" +INNER JOIN ""SplitEntityOnePart3"" AS ""s0"" ON ""s"".""Id"" = ""s0"".""Id"" +INNER JOIN ""SplitEntityOnePart2"" AS ""s1"" ON ""s"".""Id"" = ""s1"".""Id"" +LEFT JOIN ""OwnedReferencePart3"" AS ""o"" ON ""s1"".""Id"" = ""o"".""EntityOneId"""); + } + + public override async Task Tph_entity_owning_a_split_reference_on_base_without_table_sharing(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_base_without_table_sharing(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""b"".""Discriminator"", ""b"".""MiddleValue"", ""b"".""SiblingValue"", ""b"".""LeafValue"", ""o"".""BaseEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ""OwnedReferencePart1"" AS ""o"" ON ""b"".""Id"" = ""o"".""BaseEntityId"" +LEFT JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""BaseEntityId"" = ""o0"".""BaseEntityId"" +LEFT JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""BaseEntityId"" = ""o1"".""BaseEntityId"""); + } + + public override async Task Tpt_entity_owning_a_split_reference_on_base_without_table_sharing(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_base_without_table_sharing(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""m"".""MiddleValue"", ""s"".""SiblingValue"", ""l"".""LeafValue"", CASE + WHEN ""l"".""Id"" IS NOT NULL THEN 'LeafEntity' + WHEN ""s"".""Id"" IS NOT NULL THEN 'SiblingEntity' + WHEN ""m"".""Id"" IS NOT NULL THEN 'MiddleEntity' +END AS ""Discriminator"", ""o"".""BaseEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ""MiddleEntity"" AS ""m"" ON ""b"".""Id"" = ""m"".""Id"" +LEFT JOIN ""SiblingEntity"" AS ""s"" ON ""b"".""Id"" = ""s"".""Id"" +LEFT JOIN ""LeafEntity"" AS ""l"" ON ""b"".""Id"" = ""l"".""Id"" +LEFT JOIN ""OwnedReferencePart1"" AS ""o"" ON ""b"".""Id"" = ""o"".""BaseEntityId"" +LEFT JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""BaseEntityId"" = ""o0"".""BaseEntityId"" +LEFT JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""BaseEntityId"" = ""o1"".""BaseEntityId"""); + } + + public override async Task Tph_entity_owning_a_split_reference_on_middle_without_table_sharing(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_middle_without_table_sharing(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""b"".""Discriminator"", ""b"".""MiddleValue"", ""b"".""SiblingValue"", ""b"".""LeafValue"", ""o"".""MiddleEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ""OwnedReferencePart1"" AS ""o"" ON ""b"".""Id"" = ""o"".""MiddleEntityId"" +LEFT JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""MiddleEntityId"" = ""o0"".""MiddleEntityId"" +LEFT JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""MiddleEntityId"" = ""o1"".""MiddleEntityId"""); + } + + public override async Task Tpt_entity_owning_a_split_reference_on_middle_without_table_sharing(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_middle_without_table_sharing(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""m"".""MiddleValue"", ""s"".""SiblingValue"", ""l"".""LeafValue"", CASE + WHEN ""l"".""Id"" IS NOT NULL THEN 'LeafEntity' + WHEN ""s"".""Id"" IS NOT NULL THEN 'SiblingEntity' + WHEN ""m"".""Id"" IS NOT NULL THEN 'MiddleEntity' +END AS ""Discriminator"", ""o"".""MiddleEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ""MiddleEntity"" AS ""m"" ON ""b"".""Id"" = ""m"".""Id"" +LEFT JOIN ""SiblingEntity"" AS ""s"" ON ""b"".""Id"" = ""s"".""Id"" +LEFT JOIN ""LeafEntity"" AS ""l"" ON ""b"".""Id"" = ""l"".""Id"" +LEFT JOIN ""OwnedReferencePart1"" AS ""o"" ON ""b"".""Id"" = ""o"".""MiddleEntityId"" +LEFT JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""MiddleEntityId"" = ""o0"".""MiddleEntityId"" +LEFT JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""MiddleEntityId"" = ""o1"".""MiddleEntityId"""); + } + + public override async Task Tph_entity_owning_a_split_reference_on_leaf_without_table_sharing(bool async) + { + await base.Tph_entity_owning_a_split_reference_on_leaf_without_table_sharing(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""b"".""Discriminator"", ""b"".""MiddleValue"", ""b"".""SiblingValue"", ""b"".""LeafValue"", ""o"".""LeafEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ""OwnedReferencePart1"" AS ""o"" ON ""b"".""Id"" = ""o"".""LeafEntityId"" +LEFT JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""LeafEntityId"" = ""o0"".""LeafEntityId"" +LEFT JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""LeafEntityId"" = ""o1"".""LeafEntityId"""); + } + + public override async Task Tpt_entity_owning_a_split_reference_on_leaf_without_table_sharing(bool async) + { + await base.Tpt_entity_owning_a_split_reference_on_leaf_without_table_sharing(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""m"".""MiddleValue"", ""s"".""SiblingValue"", ""l"".""LeafValue"", CASE + WHEN ""l"".""Id"" IS NOT NULL THEN 'LeafEntity' + WHEN ""s"".""Id"" IS NOT NULL THEN 'SiblingEntity' + WHEN ""m"".""Id"" IS NOT NULL THEN 'MiddleEntity' +END AS ""Discriminator"", ""o"".""LeafEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ""MiddleEntity"" AS ""m"" ON ""b"".""Id"" = ""m"".""Id"" +LEFT JOIN ""SiblingEntity"" AS ""s"" ON ""b"".""Id"" = ""s"".""Id"" +LEFT JOIN ""LeafEntity"" AS ""l"" ON ""b"".""Id"" = ""l"".""Id"" +LEFT JOIN ""OwnedReferencePart1"" AS ""o"" ON ""b"".""Id"" = ""o"".""LeafEntityId"" +LEFT JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""LeafEntityId"" = ""o0"".""LeafEntityId"" +LEFT JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""LeafEntityId"" = ""o1"".""LeafEntityId"""); + } + + public override async Task Tpc_entity_owning_a_split_reference_on_leaf_without_table_sharing(bool async) + { + await base.Tpc_entity_owning_a_split_reference_on_leaf_without_table_sharing(async); + + AssertSql( + @"SELECT ""t"".""Id"", ""t"".""BaseValue"", ""t"".""MiddleValue"", ""t"".""SiblingValue"", ""t"".""LeafValue"", ""t"".""Discriminator"", ""o"".""LeafEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" +FROM ( + SELECT ""b"".""Id"", ""b"".""BaseValue"", NULL AS ""MiddleValue"", NULL AS ""SiblingValue"", NULL AS ""LeafValue"", 'BaseEntity' AS ""Discriminator"" + FROM ""BaseEntity"" AS ""b"" + UNION ALL + SELECT ""m"".""Id"", ""m"".""BaseValue"", ""m"".""MiddleValue"", NULL AS ""SiblingValue"", NULL AS ""LeafValue"", 'MiddleEntity' AS ""Discriminator"" + FROM ""MiddleEntity"" AS ""m"" + UNION ALL + SELECT ""s"".""Id"", ""s"".""BaseValue"", NULL AS ""MiddleValue"", ""s"".""SiblingValue"", NULL AS ""LeafValue"", 'SiblingEntity' AS ""Discriminator"" + FROM ""SiblingEntity"" AS ""s"" + UNION ALL + SELECT ""l"".""Id"", ""l"".""BaseValue"", ""l"".""MiddleValue"", NULL AS ""SiblingValue"", ""l"".""LeafValue"", 'LeafEntity' AS ""Discriminator"" + FROM ""LeafEntity"" AS ""l"" +) AS ""t"" +LEFT JOIN ""OwnedReferencePart1"" AS ""o"" ON ""t"".""Id"" = ""o"".""LeafEntityId"" +LEFT JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""LeafEntityId"" = ""o0"".""LeafEntityId"" +LEFT JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""LeafEntityId"" = ""o1"".""LeafEntityId"""); + } + + public override async Task Tph_entity_owning_a_split_collection_on_base(bool async) + { + await base.Tph_entity_owning_a_split_collection_on_base(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""b"".""Discriminator"", ""b"".""MiddleValue"", ""b"".""SiblingValue"", ""b"".""LeafValue"", ""t"".""BaseEntityId"", ""t"".""Id"", ""t"".""OwnedIntValue1"", ""t"".""OwnedIntValue2"", ""t"".""OwnedIntValue3"", ""t"".""OwnedIntValue4"", ""t"".""OwnedStringValue1"", ""t"".""OwnedStringValue2"", ""t"".""OwnedStringValue3"", ""t"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ( + SELECT ""o"".""BaseEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" + FROM ""OwnedReferencePart1"" AS ""o"" + INNER JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""BaseEntityId"" = ""o0"".""BaseEntityId"" AND ""o"".""Id"" = ""o0"".""Id"" + INNER JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""BaseEntityId"" = ""o1"".""BaseEntityId"" AND ""o"".""Id"" = ""o1"".""Id"" +) AS ""t"" ON ""b"".""Id"" = ""t"".""BaseEntityId"" +ORDER BY ""b"".""Id"", ""t"".""BaseEntityId"""); + } + + public override async Task Tpt_entity_owning_a_split_collection_on_base(bool async) + { + await base.Tpt_entity_owning_a_split_collection_on_base(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""m"".""MiddleValue"", ""s"".""SiblingValue"", ""l"".""LeafValue"", CASE + WHEN ""l"".""Id"" IS NOT NULL THEN 'LeafEntity' + WHEN ""s"".""Id"" IS NOT NULL THEN 'SiblingEntity' + WHEN ""m"".""Id"" IS NOT NULL THEN 'MiddleEntity' +END AS ""Discriminator"", ""t"".""BaseEntityId"", ""t"".""Id"", ""t"".""OwnedIntValue1"", ""t"".""OwnedIntValue2"", ""t"".""OwnedIntValue3"", ""t"".""OwnedIntValue4"", ""t"".""OwnedStringValue1"", ""t"".""OwnedStringValue2"", ""t"".""OwnedStringValue3"", ""t"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ""MiddleEntity"" AS ""m"" ON ""b"".""Id"" = ""m"".""Id"" +LEFT JOIN ""SiblingEntity"" AS ""s"" ON ""b"".""Id"" = ""s"".""Id"" +LEFT JOIN ""LeafEntity"" AS ""l"" ON ""b"".""Id"" = ""l"".""Id"" +LEFT JOIN ( + SELECT ""o"".""BaseEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" + FROM ""OwnedReferencePart1"" AS ""o"" + INNER JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""BaseEntityId"" = ""o0"".""BaseEntityId"" AND ""o"".""Id"" = ""o0"".""Id"" + INNER JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""BaseEntityId"" = ""o1"".""BaseEntityId"" AND ""o"".""Id"" = ""o1"".""Id"" +) AS ""t"" ON ""b"".""Id"" = ""t"".""BaseEntityId"" +ORDER BY ""b"".""Id"", ""t"".""BaseEntityId"""); + } + + public override async Task Tph_entity_owning_a_split_collection_on_middle(bool async) + { + await base.Tph_entity_owning_a_split_collection_on_middle(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""b"".""Discriminator"", ""b"".""MiddleValue"", ""b"".""SiblingValue"", ""b"".""LeafValue"", ""t"".""MiddleEntityId"", ""t"".""Id"", ""t"".""OwnedIntValue1"", ""t"".""OwnedIntValue2"", ""t"".""OwnedIntValue3"", ""t"".""OwnedIntValue4"", ""t"".""OwnedStringValue1"", ""t"".""OwnedStringValue2"", ""t"".""OwnedStringValue3"", ""t"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ( + SELECT ""o"".""MiddleEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" + FROM ""OwnedReferencePart1"" AS ""o"" + INNER JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""MiddleEntityId"" = ""o0"".""MiddleEntityId"" AND ""o"".""Id"" = ""o0"".""Id"" + INNER JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""MiddleEntityId"" = ""o1"".""MiddleEntityId"" AND ""o"".""Id"" = ""o1"".""Id"" +) AS ""t"" ON ""b"".""Id"" = ""t"".""MiddleEntityId"" +ORDER BY ""b"".""Id"", ""t"".""MiddleEntityId"""); + } + + public override async Task Tpt_entity_owning_a_split_collection_on_middle(bool async) + { + await base.Tpt_entity_owning_a_split_collection_on_middle(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""m"".""MiddleValue"", ""s"".""SiblingValue"", ""l"".""LeafValue"", CASE + WHEN ""l"".""Id"" IS NOT NULL THEN 'LeafEntity' + WHEN ""s"".""Id"" IS NOT NULL THEN 'SiblingEntity' + WHEN ""m"".""Id"" IS NOT NULL THEN 'MiddleEntity' +END AS ""Discriminator"", ""t"".""MiddleEntityId"", ""t"".""Id"", ""t"".""OwnedIntValue1"", ""t"".""OwnedIntValue2"", ""t"".""OwnedIntValue3"", ""t"".""OwnedIntValue4"", ""t"".""OwnedStringValue1"", ""t"".""OwnedStringValue2"", ""t"".""OwnedStringValue3"", ""t"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ""MiddleEntity"" AS ""m"" ON ""b"".""Id"" = ""m"".""Id"" +LEFT JOIN ""SiblingEntity"" AS ""s"" ON ""b"".""Id"" = ""s"".""Id"" +LEFT JOIN ""LeafEntity"" AS ""l"" ON ""b"".""Id"" = ""l"".""Id"" +LEFT JOIN ( + SELECT ""o"".""MiddleEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" + FROM ""OwnedReferencePart1"" AS ""o"" + INNER JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""MiddleEntityId"" = ""o0"".""MiddleEntityId"" AND ""o"".""Id"" = ""o0"".""Id"" + INNER JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""MiddleEntityId"" = ""o1"".""MiddleEntityId"" AND ""o"".""Id"" = ""o1"".""Id"" +) AS ""t"" ON ""b"".""Id"" = ""t"".""MiddleEntityId"" +ORDER BY ""b"".""Id"", ""t"".""MiddleEntityId"""); + } + + public override async Task Tph_entity_owning_a_split_collection_on_leaf(bool async) + { + await base.Tph_entity_owning_a_split_collection_on_leaf(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""b"".""Discriminator"", ""b"".""MiddleValue"", ""b"".""SiblingValue"", ""b"".""LeafValue"", ""t"".""LeafEntityId"", ""t"".""Id"", ""t"".""OwnedIntValue1"", ""t"".""OwnedIntValue2"", ""t"".""OwnedIntValue3"", ""t"".""OwnedIntValue4"", ""t"".""OwnedStringValue1"", ""t"".""OwnedStringValue2"", ""t"".""OwnedStringValue3"", ""t"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ( + SELECT ""o"".""LeafEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" + FROM ""OwnedReferencePart1"" AS ""o"" + INNER JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""LeafEntityId"" = ""o0"".""LeafEntityId"" AND ""o"".""Id"" = ""o0"".""Id"" + INNER JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""LeafEntityId"" = ""o1"".""LeafEntityId"" AND ""o"".""Id"" = ""o1"".""Id"" +) AS ""t"" ON ""b"".""Id"" = ""t"".""LeafEntityId"" +ORDER BY ""b"".""Id"", ""t"".""LeafEntityId"""); + } + + public override async Task Tpt_entity_owning_a_split_collection_on_leaf(bool async) + { + await base.Tpt_entity_owning_a_split_collection_on_leaf(async); + + AssertSql( + @"SELECT ""b"".""Id"", ""b"".""BaseValue"", ""m"".""MiddleValue"", ""s"".""SiblingValue"", ""l"".""LeafValue"", CASE + WHEN ""l"".""Id"" IS NOT NULL THEN 'LeafEntity' + WHEN ""s"".""Id"" IS NOT NULL THEN 'SiblingEntity' + WHEN ""m"".""Id"" IS NOT NULL THEN 'MiddleEntity' +END AS ""Discriminator"", ""t"".""LeafEntityId"", ""t"".""Id"", ""t"".""OwnedIntValue1"", ""t"".""OwnedIntValue2"", ""t"".""OwnedIntValue3"", ""t"".""OwnedIntValue4"", ""t"".""OwnedStringValue1"", ""t"".""OwnedStringValue2"", ""t"".""OwnedStringValue3"", ""t"".""OwnedStringValue4"" +FROM ""BaseEntity"" AS ""b"" +LEFT JOIN ""MiddleEntity"" AS ""m"" ON ""b"".""Id"" = ""m"".""Id"" +LEFT JOIN ""SiblingEntity"" AS ""s"" ON ""b"".""Id"" = ""s"".""Id"" +LEFT JOIN ""LeafEntity"" AS ""l"" ON ""b"".""Id"" = ""l"".""Id"" +LEFT JOIN ( + SELECT ""o"".""LeafEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" + FROM ""OwnedReferencePart1"" AS ""o"" + INNER JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""LeafEntityId"" = ""o0"".""LeafEntityId"" AND ""o"".""Id"" = ""o0"".""Id"" + INNER JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""LeafEntityId"" = ""o1"".""LeafEntityId"" AND ""o"".""Id"" = ""o1"".""Id"" +) AS ""t"" ON ""b"".""Id"" = ""t"".""LeafEntityId"" +ORDER BY ""b"".""Id"", ""t"".""LeafEntityId"""); + } + + public override async Task Tpc_entity_owning_a_split_collection_on_leaf(bool async) + { + await base.Tpc_entity_owning_a_split_collection_on_leaf(async); + + AssertSql( + @"SELECT ""t"".""Id"", ""t"".""BaseValue"", ""t"".""MiddleValue"", ""t"".""SiblingValue"", ""t"".""LeafValue"", ""t"".""Discriminator"", ""t0"".""LeafEntityId"", ""t0"".""Id"", ""t0"".""OwnedIntValue1"", ""t0"".""OwnedIntValue2"", ""t0"".""OwnedIntValue3"", ""t0"".""OwnedIntValue4"", ""t0"".""OwnedStringValue1"", ""t0"".""OwnedStringValue2"", ""t0"".""OwnedStringValue3"", ""t0"".""OwnedStringValue4"" +FROM ( + SELECT ""b"".""Id"", ""b"".""BaseValue"", NULL AS ""MiddleValue"", NULL AS ""SiblingValue"", NULL AS ""LeafValue"", 'BaseEntity' AS ""Discriminator"" + FROM ""BaseEntity"" AS ""b"" + UNION ALL + SELECT ""m"".""Id"", ""m"".""BaseValue"", ""m"".""MiddleValue"", NULL AS ""SiblingValue"", NULL AS ""LeafValue"", 'MiddleEntity' AS ""Discriminator"" + FROM ""MiddleEntity"" AS ""m"" + UNION ALL + SELECT ""s"".""Id"", ""s"".""BaseValue"", NULL AS ""MiddleValue"", ""s"".""SiblingValue"", NULL AS ""LeafValue"", 'SiblingEntity' AS ""Discriminator"" + FROM ""SiblingEntity"" AS ""s"" + UNION ALL + SELECT ""l"".""Id"", ""l"".""BaseValue"", ""l"".""MiddleValue"", NULL AS ""SiblingValue"", ""l"".""LeafValue"", 'LeafEntity' AS ""Discriminator"" + FROM ""LeafEntity"" AS ""l"" +) AS ""t"" +LEFT JOIN ( + SELECT ""o"".""LeafEntityId"", ""o"".""Id"", ""o"".""OwnedIntValue1"", ""o"".""OwnedIntValue2"", ""o1"".""OwnedIntValue3"", ""o0"".""OwnedIntValue4"", ""o"".""OwnedStringValue1"", ""o"".""OwnedStringValue2"", ""o1"".""OwnedStringValue3"", ""o0"".""OwnedStringValue4"" + FROM ""OwnedReferencePart1"" AS ""o"" + INNER JOIN ""OwnedReferencePart4"" AS ""o0"" ON ""o"".""LeafEntityId"" = ""o0"".""LeafEntityId"" AND ""o"".""Id"" = ""o0"".""Id"" + INNER JOIN ""OwnedReferencePart3"" AS ""o1"" ON ""o"".""LeafEntityId"" = ""o1"".""LeafEntityId"" AND ""o"".""Id"" = ""o1"".""Id"" +) AS ""t0"" ON ""t"".""Id"" = ""t0"".""LeafEntityId"" +ORDER BY ""t"".""Id"", ""t0"".""LeafEntityId"""); + } }