diff --git a/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs new file mode 100644 index 00000000000..6b114042c6e --- /dev/null +++ b/src/EFCore.Relational/Query/RelationalEntityShaperExpression.cs @@ -0,0 +1,164 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.EntityFrameworkCore.Utilities; + +namespace Microsoft.EntityFrameworkCore.Query +{ + public class RelationalEntityShaperExpression : EntityShaperExpression + { + private static readonly MethodInfo _createUnableToDiscriminateException + = typeof(RelationalEntityShaperExpression).GetTypeInfo() + .GetDeclaredMethod(nameof(CreateUnableToDiscriminateException)); + + [UsedImplicitly] + private static Exception CreateUnableToDiscriminateException(IEntityType entityType, object discriminator) + => new InvalidOperationException(CoreStrings.UnableToDiscriminate(entityType.DisplayName(), discriminator?.ToString())); + public RelationalEntityShaperExpression([NotNull] IEntityType entityType, [NotNull] Expression valueBufferExpression, bool nullable) + : base(entityType, valueBufferExpression, nullable, + GenerateMaterializationCondition(Check.NotNull(entityType, nameof(entityType)), nullable)) + { + } + + public RelationalEntityShaperExpression( + [NotNull] IEntityType entityType, + [NotNull] Expression valueBufferExpression, + bool nullable, + [CanBeNull] LambdaExpression materializationCondition) + : base(entityType, valueBufferExpression, nullable, + materializationCondition ?? GenerateMaterializationCondition(Check.NotNull(entityType, nameof(entityType)), nullable)) + { + } + + private static LambdaExpression GenerateMaterializationCondition(IEntityType entityType, bool nullable) + { + var valueBufferParameter = Parameter(typeof(ValueBuffer)); + + var keyless = entityType.FindPrimaryKey() == null; + var optionalDependent = false; + if (!keyless) + { + var linkingFks = entityType.GetViewOrTableMappings().Single().Table.GetInternalForeignKeys(entityType); + if (linkingFks != null + && linkingFks.Any()) + { + optionalDependent = true; + } + } + + Expression body; + var concreteEntityTypes = entityType.GetConcreteDerivedTypesInclusive().ToArray(); + var discriminatorProperty = entityType.GetDiscriminatorProperty(); + if (discriminatorProperty != null) + { + var discriminatorValueVariable = Variable(discriminatorProperty.ClrType, "discriminator"); + var expressions = new List + { + Assign( + discriminatorValueVariable, + valueBufferParameter.CreateValueBufferReadValueExpression( + discriminatorProperty.ClrType, discriminatorProperty.GetIndex(), discriminatorProperty)) + }; + + var switchCases = new SwitchCase[concreteEntityTypes.Length]; + for (var i = 0; i < concreteEntityTypes.Length; i++) + { + var discriminatorValue = Constant(concreteEntityTypes[i].GetDiscriminatorValue(), discriminatorProperty.ClrType); + switchCases[i] = SwitchCase(Constant(concreteEntityTypes[i], typeof(IEntityType)), discriminatorValue); + } + + var defaultBlock = Block( + Throw(Call( + _createUnableToDiscriminateException, Constant(entityType), Convert(discriminatorValueVariable, typeof(object)))), + Default(typeof(IEntityType))); + + expressions.Add(Switch(discriminatorValueVariable, defaultBlock, switchCases)); + body = Block(new[] { discriminatorValueVariable }, expressions); + } + else + { + body = Constant(concreteEntityTypes.Length == 1 ? concreteEntityTypes[0] : entityType, typeof(IEntityType)); + } + + if (optionalDependent) + { + var requiredNonPkProperties = entityType.GetProperties().Where(p => !p.IsNullable && !p.IsPrimaryKey()).ToList(); + if (requiredNonPkProperties.Count > 0) + { + body = Condition( + requiredNonPkProperties + .Select(p => NotEqual( + valueBufferParameter.CreateValueBufferReadValueExpression(typeof(object), p.GetIndex(), p), + Constant(null))) + .Aggregate((a, b) => AndAlso(a, b)), + body, + Default(typeof(IEntityType))); + } + else + { + var allNonPkProperties = entityType.GetProperties().Where(p => !p.IsPrimaryKey()).ToList(); + if (allNonPkProperties.Count > 0) + { + body = Condition( + allNonPkProperties + .Select(p => NotEqual( + valueBufferParameter.CreateValueBufferReadValueExpression(typeof(object), p.GetIndex(), p), + Constant(null))) + .Aggregate((a, b) => OrElse(a, b)), + body, + Default(typeof(IEntityType))); + } + } + } + else if (keyless + && nullable) + { + body = Condition( + entityType.GetProperties() + .Select(p => NotEqual( + valueBufferParameter.CreateValueBufferReadValueExpression(typeof(object), p.GetIndex(), p), + Constant(null))) + .Aggregate((a, b) => OrElse(a, b)), + body, + Default(typeof(IEntityType))); + } + + return Lambda(body, valueBufferParameter); + } + + public override EntityShaperExpression WithEntityType(IEntityType entityType) + { + Check.NotNull(entityType, nameof(entityType)); + + return entityType != EntityType + ? new RelationalEntityShaperExpression(entityType, ValueBufferExpression, IsNullable) + : this; + } + + public override EntityShaperExpression MarkAsNullable() + => !IsNullable + // Marking nullable requires recomputation of Discriminator condition + ? new RelationalEntityShaperExpression(EntityType, ValueBufferExpression, true) + : this; + + public override EntityShaperExpression Update(Expression valueBufferExpression) + { + Check.NotNull(valueBufferExpression, nameof(valueBufferExpression)); + + return valueBufferExpression != ValueBufferExpression + ? new RelationalEntityShaperExpression(EntityType, valueBufferExpression, IsNullable, MaterializationCondition) + : this; + } + } +} diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index 34835979deb..55eb3e54572 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -133,7 +133,7 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(IEntityType private static ShapedQueryExpression CreateShapedQueryExpression(IEntityType entityType, SelectExpression selectExpression) => new ShapedQueryExpression( selectExpression, - new EntityShaperExpression( + new RelationalEntityShaperExpression( entityType, new ProjectionBindingExpression( selectExpression, @@ -1223,37 +1223,96 @@ private Expression TryExpand(Expression source, MemberIdentity member) var innerShaper = entityProjectionExpression.BindNavigation(navigation); if (innerShaper == null) { - var innerSelectExpression = _sqlExpressionFactory.Select(targetEntityType); - var innerShapedQuery = CreateShapedQueryExpression(targetEntityType, innerSelectExpression); - - var makeNullable = foreignKey.PrincipalKey.Properties - .Concat(foreignKey.Properties) - .Select(p => p.ClrType) - .Any(t => t.IsNullableType()); - - var outerKey = entityShaperExpression.CreateKeyAccessExpression( - navigation.IsOnDependent - ? foreignKey.Properties - : foreignKey.PrincipalKey.Properties, - makeNullable); - var innerKey = innerShapedQuery.ShaperExpression.CreateKeyAccessExpression( - navigation.IsOnDependent - ? foreignKey.PrincipalKey.Properties - : foreignKey.Properties, - makeNullable); + if (entityType.GetViewOrTableMappings().Single().Table + .GetReferencingInternalForeignKeys(foreignKey.PrincipalEntityType)?.Contains(foreignKey) == true) + { + // Since we are not going to update table or visit, we always generate propertyExpressions + // We just first column of PK to figure out the base table + var identifyingColumn = entityProjectionExpression.BindProperty(entityType.FindPrimaryKey().Properties.First()); + var propertyExpressions = identifyingColumn.Table is TableExpression innerTable + ? GetPropertyExpressionsFromTable(targetEntityType, innerTable, identifyingColumn.IsNullable) + // Pull columns out of inner subquery + : GetPropertyExpressionsFromSubquery(targetEntityType, identifyingColumn, identifyingColumn.IsNullable); + + innerShaper = new RelationalEntityShaperExpression( + targetEntityType, new EntityProjectionExpression(targetEntityType, propertyExpressions), true); + } + else + { + var innerSelectExpression = _sqlExpressionFactory.Select(targetEntityType); + var innerShapedQuery = CreateShapedQueryExpression(targetEntityType, innerSelectExpression); + + var makeNullable = foreignKey.PrincipalKey.Properties + .Concat(foreignKey.Properties) + .Select(p => p.ClrType) + .Any(t => t.IsNullableType()); + + var outerKey = entityShaperExpression.CreateKeyAccessExpression( + navigation.IsOnDependent + ? foreignKey.Properties + : foreignKey.PrincipalKey.Properties, + makeNullable); + var innerKey = innerShapedQuery.ShaperExpression.CreateKeyAccessExpression( + navigation.IsOnDependent + ? foreignKey.PrincipalKey.Properties + : foreignKey.Properties, + makeNullable); + + var joinPredicate = _sqlTranslator.Translate(Expression.Equal(outerKey, innerKey)); + _selectExpression.AddLeftJoin(innerSelectExpression, joinPredicate, null); + var leftJoinTable = ((LeftJoinExpression)_selectExpression.Tables.Last()).Table; + innerShaper = new RelationalEntityShaperExpression( + targetEntityType, + new EntityProjectionExpression(targetEntityType, leftJoinTable, true), + true); + } - var joinPredicate = _sqlTranslator.Translate(Expression.Equal(outerKey, innerKey)); - _selectExpression.AddLeftJoin(innerSelectExpression, joinPredicate, null); - var leftJoinTable = ((LeftJoinExpression)_selectExpression.Tables.Last()).Table; - innerShaper = new EntityShaperExpression( - targetEntityType, - new EntityProjectionExpression(targetEntityType, leftJoinTable, true), - true); entityProjectionExpression.AddNavigationBinding(navigation, innerShaper); } return innerShaper; } + + + + private static IDictionary LiftPropertyExpressionsFromSubquery( + IDictionary propertyExpressions, SelectExpression subquery) + { + var newPropertyExpressions = new Dictionary(); + foreach (var item in propertyExpressions) + { + newPropertyExpressions[item.Key] = new ColumnExpression( + subquery.Projection[subquery.AddToProjection(item.Value)], subquery); + } + + return newPropertyExpressions; + } + + private static IDictionary GetPropertyExpressionsFromSubquery( + IEntityType entityType, ColumnExpression identifyingColumn, bool nullable) + { + var subquery = (SelectExpression)identifyingColumn.Table; + var subqueryIdentifyingColumn = (ColumnExpression)subquery.Projection + .SingleOrDefault(e => string.Equals(e.Alias, identifyingColumn.Name, StringComparison.OrdinalIgnoreCase)).Expression; + + var subqueryPropertyExpressions = subqueryIdentifyingColumn.Table is TableExpression innerTable + ? GetPropertyExpressionsFromTable(entityType, innerTable, nullable) + : GetPropertyExpressionsFromSubquery(entityType, subqueryIdentifyingColumn, nullable); + + return LiftPropertyExpressionsFromSubquery(subqueryPropertyExpressions, subquery); + } + + private static IDictionary GetPropertyExpressionsFromTable( + IEntityType entityType, TableExpression table, bool nullable) + { + var propertyExpressions = new Dictionary(); + foreach (var property in entityType.GetTypesInHierarchy().SelectMany(EntityTypeExtensions.GetDeclaredProperties)) + { + propertyExpressions[property] = new ColumnExpression(property, table, nullable || !property.IsPrimaryKey()); + } + + return propertyExpressions; + } } private ShapedQueryExpression AggregateResultShaper( diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index 5034bf648a0..c727535c53c 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -66,7 +66,7 @@ private SelectExpression( } internal SelectExpression(SqlExpression projection) - :base(null) + : base(null) { if (projection != null) { @@ -874,17 +874,18 @@ public Expression AddSingleProjection([NotNull] ShapedQueryExpression shapedQuer // Joined SelectExpression may different based on left join or outer apply // And it will always be SelectExpression because of presence of Take(1) // So we need to remap projections from that SelectExpression to outer SelectExpression - var addedSelectExperssion = (SelectExpression)((JoinExpressionBase)_tables[_tables.Count - 1]).Table; - var indexOffset = _projection.Count; + var addedSelectExperssion = (SelectExpression)((JoinExpressionBase)_tables[^1]).Table; + var indexMap = new int[projectionCount]; // We only take projectionCount since the subquery can have additional projections for identifiers // Which are not relevant for this translation - foreach (var projection in addedSelectExperssion.Projection.Take(projectionCount)) + for (var i = 0; i < projectionCount; i++) { - AddToProjection(MakeNullable(addedSelectExperssion.GenerateOuterColumn(projection.Expression))); + indexMap[i] = AddToProjection(MakeNullable( + addedSelectExperssion.GenerateOuterColumn(addedSelectExperssion.Projection[i].Expression))); } // We move pendingCollectionOffset if one was lifted from inner. - return new ShaperRemappingExpressionVisitor(this, innerSelectExpression, indexOffset, pendingCollectionOffset) + return new ShaperRemappingExpressionVisitor(this, innerSelectExpression, indexMap, pendingCollectionOffset) .Visit(shaperExpression); static Expression RemoveConvert(Expression expression) @@ -967,10 +968,11 @@ public Expression ApplyCollectionJoin( AppendOrdering(ordering.Update(MakeNullable(ordering.Expression))); } - var indexOffset = _projection.Count; - foreach (var projection in innerSelectExpression.Projection) + var innerProjectionCount = innerSelectExpression.Projection.Count; + var indexMap = new int[innerProjectionCount]; + for (var i = 0; i < innerProjectionCount; i++) { - AddToProjection(MakeNullable(projection.Expression)); + indexMap[i] = AddToProjection(MakeNullable(innerSelectExpression.Projection[i].Expression)); } foreach (var identifier in innerSelectExpression._identifier.Concat(innerSelectExpression._childIdentifiers)) @@ -982,7 +984,7 @@ public Expression ApplyCollectionJoin( // Inner should not have pendingCollection since we apply them first. // Shaper should not have CollectionShaperExpression as any collection would get converted to RelationalCollectionShaperExpression. - var shaperRemapper = new ShaperRemappingExpressionVisitor(this, innerSelectExpression, indexOffset, pendingCollectionOffset: 0); + var shaperRemapper = new ShaperRemappingExpressionVisitor(this, innerSelectExpression, indexMap, pendingCollectionOffset: 0); innerShaper = shaperRemapper.Visit(innerShaper); selfIdentifier = shaperRemapper.Visit(selfIdentifier); @@ -1019,16 +1021,16 @@ private sealed class ShaperRemappingExpressionVisitor : ExpressionVisitor { private readonly SelectExpression _queryExpression; private readonly SelectExpression _innerSelectExpression; - private readonly int _projectionOffset; + private readonly int[] _indexMap; private readonly int _pendingCollectionOffset; public ShaperRemappingExpressionVisitor( - SelectExpression queryExpression, SelectExpression innerSelectExpression, int projectionOffset, int pendingCollectionOffset) + SelectExpression queryExpression, SelectExpression innerSelectExpression, int[] indexMap, int pendingCollectionOffset) { _queryExpression = queryExpression; _innerSelectExpression = innerSelectExpression; - _projectionOffset = projectionOffset; _pendingCollectionOffset = pendingCollectionOffset; + _indexMap = indexMap; } protected override Expression VisitExtension(Expression extensionExpression) @@ -1038,10 +1040,8 @@ protected override Expression VisitExtension(Expression extensionExpression) switch (extensionExpression) { case ProjectionBindingExpression projectionBindingExpression: - var oldIndex = (int)GetProjectionIndex(projectionBindingExpression); - return new ProjectionBindingExpression( - _queryExpression, oldIndex + _projectionOffset, projectionBindingExpression.Type); + _queryExpression, _indexMap[(int)GetProjectionIndex(projectionBindingExpression)], projectionBindingExpression.Type); case EntityShaperExpression entityShaperExpression: var oldIndexMap = (IDictionary)GetProjectionIndex( @@ -1049,10 +1049,10 @@ protected override Expression VisitExtension(Expression extensionExpression) var indexMap = new Dictionary(); foreach (var keyValuePair in oldIndexMap) { - indexMap[keyValuePair.Key] = keyValuePair.Value + _projectionOffset; + indexMap[keyValuePair.Key] = _indexMap[keyValuePair.Value]; } - return new EntityShaperExpression( + return new RelationalEntityShaperExpression( entityShaperExpression.EntityType, new ProjectionBindingExpression(_queryExpression, indexMap), nullable: true); diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs index 6402d3956f7..97c5c8eb221 100644 --- a/src/EFCore/Properties/CoreStrings.Designer.cs +++ b/src/EFCore/Properties/CoreStrings.Designer.cs @@ -2578,6 +2578,14 @@ public static string FunctionOnClient([CanBeNull] object methodName) GetString("FunctionOnClient", nameof(methodName)), methodName); + /// + /// Materialization condition passed for entity shaper of entity type '{entityType}' is not of correct shape. Materialization condition must be LambdaExpression of 'Func<ValueBuffer, IEntityType>' + /// + public static string QueryEntityMaterializationConditionWrongShape([CanBeNull] object entityType) + => string.Format( + GetString("QueryEntityMaterializationConditionWrongShape", nameof(entityType)), + entityType); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx index 9701fad6b53..1848bc401fb 100644 --- a/src/EFCore/Properties/CoreStrings.resx +++ b/src/EFCore/Properties/CoreStrings.resx @@ -1363,4 +1363,7 @@ The '{methodName}' method is not supported because the query has switched to client-evaluation. Inspect the log to determine which query expressions are triggering client-evaluation. + + Materialization condition passed for entity shaper of entity type '{entityType}' is not of correct shape. Materialization condition must be LambdaExpression of 'Func<ValueBuffer, IEntityType>' + \ No newline at end of file diff --git a/src/EFCore/Query/EntityShaperExpression.cs b/src/EFCore/Query/EntityShaperExpression.cs index d0e34bedd61..8b417397fde 100644 --- a/src/EFCore/Query/EntityShaperExpression.cs +++ b/src/EFCore/Query/EntityShaperExpression.cs @@ -38,30 +38,29 @@ protected EntityShaperExpression( [NotNull] IEntityType entityType, [NotNull] Expression valueBufferExpression, bool nullable, - [CanBeNull] LambdaExpression discriminatorCondition) + [CanBeNull] LambdaExpression materializationCondition) { Check.NotNull(entityType, nameof(entityType)); Check.NotNull(valueBufferExpression, nameof(valueBufferExpression)); - if (discriminatorCondition == null) + if (materializationCondition == null) { - discriminatorCondition = GenerateDiscriminatorCondition(entityType, nullable); + materializationCondition = GenerateMaterializationCondition(entityType, nullable); } - else if (discriminatorCondition.Parameters.Count != 1 - || discriminatorCondition.Parameters[0].Type != typeof(ValueBuffer) - || discriminatorCondition.ReturnType != typeof(IEntityType)) + else if (materializationCondition.Parameters.Count != 1 + || materializationCondition.Parameters[0].Type != typeof(ValueBuffer) + || materializationCondition.ReturnType != typeof(IEntityType)) { - throw new InvalidOperationException( - "Discriminator condition must be lambda expression of type Func."); + throw new InvalidOperationException(CoreStrings.QueryEntityMaterializationConditionWrongShape(entityType.DisplayName())); } EntityType = entityType; ValueBufferExpression = valueBufferExpression; IsNullable = nullable; - DiscriminatorCondition = discriminatorCondition; + MaterializationCondition = materializationCondition; } - private LambdaExpression GenerateDiscriminatorCondition(IEntityType entityType, bool nullable) + private LambdaExpression GenerateMaterializationCondition(IEntityType entityType, bool nullable) { var valueBufferParameter = Parameter(typeof(ValueBuffer)); Expression body; @@ -117,7 +116,7 @@ private LambdaExpression GenerateDiscriminatorCondition(IEntityType entityType, public virtual IEntityType EntityType { get; } public virtual Expression ValueBufferExpression { get; } public virtual bool IsNullable { get; } - public virtual LambdaExpression DiscriminatorCondition { get; } + public virtual LambdaExpression MaterializationCondition { get; } protected override Expression VisitChildren(ExpressionVisitor visitor) { @@ -139,7 +138,7 @@ public virtual EntityShaperExpression WithEntityType([NotNull] IEntityType entit public virtual EntityShaperExpression MarkAsNullable() => !IsNullable - // Marking nullable requires recomputation of Discriminator condition + // Marking nullable requires recomputation of materialization condition ? new EntityShaperExpression(EntityType, ValueBufferExpression, true) : this; @@ -148,7 +147,7 @@ public virtual EntityShaperExpression Update([NotNull] Expression valueBufferExp Check.NotNull(valueBufferExpression, nameof(valueBufferExpression)); return valueBufferExpression != ValueBufferExpression - ? new EntityShaperExpression(EntityType, valueBufferExpression, IsNullable, DiscriminatorCondition) + ? new EntityShaperExpression(EntityType, valueBufferExpression, IsNullable, MaterializationCondition) : this; } diff --git a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs index 2a6e633f5f7..bdabc2ac0f5 100644 --- a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs @@ -386,7 +386,7 @@ private Expression ProcessEntityShaper(EntityShaperExpression entityShaperExpres Expression.IfThenElse( Expression.NotEqual( entryVariable, - Expression.Constant(default(InternalEntityEntry), typeof(InternalEntityEntry))), + Expression.Default(typeof(InternalEntityEntry))), Expression.Block( Expression.Assign( concreteEntityTypeVariable, @@ -452,9 +452,9 @@ private Expression MaterializeEntity( expressions.Add( Expression.Assign(concreteEntityTypeVariable, ReplacingExpressionVisitor.Replace( - entityShaperExpression.DiscriminatorCondition.Parameters[0], + entityShaperExpression.MaterializationCondition.Parameters[0], valueBufferExpression, - entityShaperExpression.DiscriminatorCondition.Body))); + entityShaperExpression.MaterializationCondition.Body))); var concreteEntityTypes = entityType.GetConcreteDerivedTypesInclusive().ToArray(); var discriminatorProperty = entityType.GetDiscriminatorProperty(); @@ -489,12 +489,16 @@ private Expression MaterializeEntity( expressions.Add( Expression.Assign( - entryVariable, Expression.Call( - QueryCompilationContext.QueryContextParameter, - _startTrackingMethodInfo, - concreteEntityTypeVariable, - instanceVariable, - shadowValuesVariable))); + entryVariable, + Expression.Condition( + Expression.Equal(concreteEntityTypeVariable, Expression.Default(typeof(IEntityType))), + Expression.Default(typeof(InternalEntityEntry)), + Expression.Call( + QueryCompilationContext.QueryContextParameter, + _startTrackingMethodInfo, + concreteEntityTypeVariable, + instanceVariable, + shadowValuesVariable)))); } expressions.Add(instanceVariable); @@ -546,14 +550,6 @@ private BlockExpression CreateFullMaterializeExpression( return Expression.Block(blockExpressions); } - - private static readonly MethodInfo _createUnableToDiscriminateException - = typeof(EntityMaterializerInjectingExpressionVisitor).GetTypeInfo() - .GetDeclaredMethod(nameof(CreateUnableToDiscriminateException)); - - [UsedImplicitly] - private static Exception CreateUnableToDiscriminateException(IEntityType entityType, object discriminator) - => new InvalidOperationException(CoreStrings.UnableToDiscriminate(entityType.DisplayName(), discriminator?.ToString())); } } } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs index 271a7565002..3948eaa4cb1 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs @@ -1099,6 +1099,12 @@ FROM root c ORDER BY c[""CustomerID""]"); } + [ConditionalTheory(Skip = "Issue#17246")] + public override Task Projecting_multiple_collection_with_same_constant_works(bool async) + { + return base.Projecting_multiple_collection_with_same_constant_works(async); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs index 0acd2effebe..43571cc7c32 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs @@ -479,10 +479,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con ab.IndexedProperty("AddressLine"); ab.IndexedProperty(typeof(int), "ZipCode"); ab.HasData( - new { OwnedPersonId = 1, AddressLine = "804 S. Lakeshore Road", ZipCode = 38654 }, - new { OwnedPersonId = 2, AddressLine = "7 Church Dr.", ZipCode = 28655 }, - new { OwnedPersonId = 3, AddressLine = "72 Hickory Rd.", ZipCode = 07728 }, - new { OwnedPersonId = 4, AddressLine = "28 Strawberry St.", ZipCode = 19053 }); + new { OwnedPersonId = 1, PlaceType = "Land", AddressLine = "804 S. Lakeshore Road", ZipCode = 38654 }, + new { OwnedPersonId = 2, PlaceType = "Land", AddressLine = "7 Church Dr.", ZipCode = 28655 }, + new { OwnedPersonId = 3, PlaceType = "Land", AddressLine = "72 Hickory Rd.", ZipCode = 07728 }, + new { OwnedPersonId = 4, PlaceType = "Land", AddressLine = "28 Strawberry St.", ZipCode = 19053 }); ab.OwnsOne( a => a.Country, cb => @@ -542,8 +542,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con eb.OwnsOne( p => p.BranchAddress, ab => { + ab.IndexedProperty("BranchName"); ab.HasData( - new { BranchId = 2 }, new { BranchId = 3 }); + new { BranchId = 2, PlaceType = "Land", BranchName = "BranchA" }, + new { BranchId = 3, PlaceType = "Land", BranchName = "BranchB" }); ab.OwnsOne( a => a.Country, cb => @@ -574,8 +576,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con eb.OwnsOne( p => p.LeafAAddress, ab => { + ab.IndexedProperty("LeafType"); ab.HasData( - new { LeafAId = 3 }); + new { LeafAId = 3, PlaceType = "Land", LeafType = 1 }); ab.OwnsOne( a => a.Country, cb => @@ -600,8 +603,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con eb.OwnsOne( p => p.LeafBAddress, ab => { + ab.IndexedProperty("LeafBType"); ab.HasData( - new { LeafBId = 4 }); + new { LeafBId = 4, PlaceType = "Land", LeafBType = "Green" }); ab.OwnsOne( a => a.Country, cb => diff --git a/test/EFCore.Relational.Specification.Tests/Query/RelationalOwnedQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/RelationalOwnedQueryTestBase.cs index 152c6fb9b2e..5f8fc1b718c 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/RelationalOwnedQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/RelationalOwnedQueryTestBase.cs @@ -28,6 +28,17 @@ protected override QueryAsserter CreateQueryAsserter( entitySorters, entityAsserters, CanExecuteQueryString); + + protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context) + { + base.OnModelCreating(modelBuilder, context); + + // TODO: See issue#20334 + //modelBuilder.Entity().OwnsOne(e => e.PersonAddress).Property(e => e.PlaceType).HasColumnName("PlaceType"); + //modelBuilder.Entity().OwnsOne(e => e.BranchAddress).Property(e => e.PlaceType).HasColumnName("PlaceType"); + //modelBuilder.Entity().OwnsOne(e => e.LeafAAddress).Property(e => e.PlaceType).HasColumnName("PlaceType"); + //modelBuilder.Entity().OwnsOne(e => e.LeafBAddress).Property(e => e.PlaceType).HasColumnName("PlaceType"); + } } } } diff --git a/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs index 4f36cb1a330..1f7c39b981c 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs @@ -1717,5 +1717,25 @@ private class IdName public T Id { get; set; } public string Name { get; set; } } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Projecting_multiple_collection_with_same_constant_works(bool async) + { + return AssertQuery( + async, + ss => ss.Set().Where(c => c.CustomerID == "ALFKI") + .Select(c => new + { + O1 = c.Orders.Select(e => new { Value = 1 }), + O2 = c.Orders.Select(e => new { AnotherValue = 1 }) + }), + assertOrder: true, //single element + elementAsserter: (e, a) => + { + AssertCollection(e.O1, a.O1, ordered: true); + AssertCollection(e.O2, a.O2, ordered: true); + }); + } } } diff --git a/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs index c7728b33983..77c2dd3f371 100644 --- a/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs @@ -750,6 +750,10 @@ private static void AssertAddress(OwnedAddress expectedAddress, OwnedAddress act { Assert.Equal(expectedAddress["AddressLine"], actualAddress["AddressLine"]); Assert.Equal(expectedAddress["ZipCode"], actualAddress["ZipCode"]); + Assert.Equal(expectedAddress["BranchName"], actualAddress["BranchName"]); + Assert.Equal(expectedAddress["LeafType"], actualAddress["LeafType"]); + Assert.Equal(expectedAddress["LeafBType"], actualAddress["LeafBType"]); + Assert.Equal(expectedAddress.PlaceType, actualAddress.PlaceType); Assert.Equal(expectedAddress.Country.PlanetId, actualAddress.Country.PlanetId); Assert.Equal(expectedAddress.Country.Name, actualAddress.Country.Name); } @@ -1042,10 +1046,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con ab.IndexedProperty("AddressLine"); ab.IndexedProperty(typeof(int), "ZipCode"); ab.HasData( - new { OwnedPersonId = 1, AddressLine = "804 S. Lakeshore Road", ZipCode = 38654 }, - new { OwnedPersonId = 2, AddressLine = "7 Church Dr.", ZipCode = 28655 }, - new { OwnedPersonId = 3, AddressLine = "72 Hickory Rd.", ZipCode = 07728 }, - new { OwnedPersonId = 4, AddressLine = "28 Strawberry St.", ZipCode = 19053 }); + new { OwnedPersonId = 1, PlaceType = "Land", AddressLine = "804 S. Lakeshore Road", ZipCode = 38654 }, + new { OwnedPersonId = 2, PlaceType = "Land", AddressLine = "7 Church Dr.", ZipCode = 28655 }, + new { OwnedPersonId = 3, PlaceType = "Land", AddressLine = "72 Hickory Rd.", ZipCode = 07728 }, + new { OwnedPersonId = 4, PlaceType = "Land", AddressLine = "28 Strawberry St.", ZipCode = 19053 }); ab.OwnsOne( a => a.Country, cb => @@ -1103,8 +1107,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con eb.OwnsOne( p => p.BranchAddress, ab => { + ab.IndexedProperty("BranchName"); ab.HasData( - new { BranchId = 2 }, new { BranchId = 3 }); + new { BranchId = 2, PlaceType = "Land", BranchName = "BranchA" }, + new { BranchId = 3, PlaceType = "Land", BranchName = "BranchB" }); ab.OwnsOne( a => a.Country, cb => @@ -1136,8 +1142,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con eb.OwnsOne( p => p.LeafAAddress, ab => { + ab.IndexedProperty("LeafType"); + ab.HasData( - new { LeafAId = 3 }); + new { LeafAId = 3, PlaceType = "Land", LeafType = 1 }); ab.OwnsOne( a => a.Country, cb => @@ -1166,8 +1174,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con eb.OwnsOne( p => p.LeafBAddress, ab => { + ab.IndexedProperty("LeafBType"); ab.HasData( - new { LeafBId = 4 }); + new { LeafBId = 4, PlaceType = "Land", LeafBType = "Green" }); ab.OwnsOne( a => a.Country, cb => @@ -1354,7 +1363,7 @@ private static IReadOnlyList CreateMoons() private static IReadOnlyList CreateOwnedPeople() { - var personAddress1 = new OwnedAddress { Country = new OwnedCountry { Name = "USA", PlanetId = 1 } }; + var personAddress1 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "USA", PlanetId = 1 } }; personAddress1["AddressLine"] = "804 S. Lakeshore Road"; personAddress1["ZipCode"] = 38654; var ownedPerson1 = new OwnedPerson @@ -1364,37 +1373,46 @@ private static IReadOnlyList CreateOwnedPeople() }; ownedPerson1["Name"] = "Mona Cy"; - var personAddress2 = new OwnedAddress { Country = new OwnedCountry { Name = "USA", PlanetId = 1 } }; + var personAddress2 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "USA", PlanetId = 1 } }; personAddress2["AddressLine"] = "7 Church Dr."; personAddress2["ZipCode"] = 28655; + var branchAddress2 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "Canada", PlanetId = 1 } }; + branchAddress2["BranchName"] = "BranchA"; + var ownedPerson2 = new Branch { Id = 2, PersonAddress = personAddress2, - BranchAddress = new OwnedAddress { Country = new OwnedCountry { Name = "Canada", PlanetId = 1 } } + BranchAddress = branchAddress2 }; ownedPerson2["Name"] = "Antigonus Mitul"; - var personAddress3 = new OwnedAddress { Country = new OwnedCountry { Name = "USA", PlanetId = 1 } }; + var personAddress3 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "USA", PlanetId = 1 } }; personAddress3["AddressLine"] = "72 Hickory Rd."; personAddress3["ZipCode"] = 07728; + var branchAddress3 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "Canada", PlanetId = 1 } }; + branchAddress3["BranchName"] = "BranchB"; + var leafAAddress3 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "Mexico", PlanetId = 1 } }; + leafAAddress3["LeafType"] = 1; var ownedPerson3 = new LeafA { Id = 3, PersonAddress = personAddress3, - BranchAddress = new OwnedAddress { Country = new OwnedCountry { Name = "Canada", PlanetId = 1 } }, - LeafAAddress = new OwnedAddress { Country = new OwnedCountry { Name = "Mexico", PlanetId = 1 } } + BranchAddress = branchAddress3, + LeafAAddress = leafAAddress3 }; ownedPerson3["Name"] = "Madalena Morana"; - var personAddress4 = new OwnedAddress { Country = new OwnedCountry { Name = "USA", PlanetId = 1 } }; + var personAddress4 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "USA", PlanetId = 1 } }; personAddress4["AddressLine"] = "28 Strawberry St."; personAddress4["ZipCode"] = 19053; + var leafBAddress4 = new OwnedAddress { PlaceType = "Land", Country = new OwnedCountry { Name = "Panama", PlanetId = 1 } }; + leafBAddress4["LeafBType"] = "Green"; var ownedPerson4 = new LeafB { Id = 4, PersonAddress = personAddress4, - LeafBAddress = new OwnedAddress { Country = new OwnedCountry { Name = "Panama", PlanetId = 1 } } + LeafBAddress = leafBAddress4 }; ownedPerson4["Name"] = "Vanda Waldemar"; @@ -1474,37 +1492,50 @@ protected class OwnedAddress { private string _addressLine; private int _zipCode; + private string _branchName; + private int _leafAType; + private string _leafBType; + + public string PlaceType { get; set; } public OwnedCountry Country { get; set; } public object this[string name] { - get + get => name switch { - if (string.Equals(name, "AddressLine", StringComparison.Ordinal)) - { - return _addressLine; - } - - if (string.Equals(name, "ZipCode", StringComparison.Ordinal)) - { - return _zipCode; - } - - throw new InvalidOperationException($"Indexer property with key {name} is not defined on {nameof(OwnedPerson)}."); - } + "AddressLine" => _addressLine, + "ZipCode" => _zipCode, + "BranchName" => _branchName, + "LeafType" => _leafAType, + "LeafBType" => _leafBType, + _ => throw new InvalidOperationException($"Indexer property with key {name} is not defined on {nameof(OwnedPerson)}."), + }; set { - if (string.Equals(name, "AddressLine", StringComparison.Ordinal)) - { - _addressLine = (string)value; - } - else if (string.Equals(name, "ZipCode", StringComparison.Ordinal)) - { - _zipCode = (int)value; - } - else + switch (name) { - throw new InvalidOperationException($"Indexer property with key {name} is not defined on {nameof(OwnedPerson)}."); + case "AddressLine": + _addressLine = (string)value; + break; + + case "ZipCode": + _zipCode = (int)value; + break; + + case "BranchName": + _branchName = (string)value; + break; + + case "LeafType": + _leafAType = (int)value; + break; + + case "LeafBType": + _leafBType = (string)value; + break; + + default: + throw new InvalidOperationException($"Indexer property with key {name} is not defined on {nameof(OwnedPerson)}."); } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/DataAnnotationSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/DataAnnotationSqlServerTest.cs index 21cfa1d7a5f..d15a542edb7 100644 --- a/test/EFCore.SqlServer.FunctionalTests/DataAnnotationSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/DataAnnotationSqlServerTest.cs @@ -148,32 +148,12 @@ public override void ConcurrencyCheckAttribute_throws_if_value_in_database_chang base.ConcurrencyCheckAttribute_throws_if_value_in_database_changed(); AssertSql( - @"SELECT TOP(1) [s].[UniqueNo], [s].[MaxLengthProperty], [s].[Name], [s].[RowVersion], [t].[UniqueNo], [t].[AdditionalDetails_Name], [t0].[UniqueNo], [t0].[Details_Name] + @"SELECT TOP(1) [s].[UniqueNo], [s].[MaxLengthProperty], [s].[Name], [s].[RowVersion], [s].[AdditionalDetails_Name], [s].[Details_Name] FROM [Sample] AS [s] -LEFT JOIN ( - SELECT [s0].[UniqueNo], [s0].[AdditionalDetails_Name] - FROM [Sample] AS [s0] - WHERE [s0].[AdditionalDetails_Name] IS NOT NULL -) AS [t] ON [s].[UniqueNo] = [t].[UniqueNo] -LEFT JOIN ( - SELECT [s1].[UniqueNo], [s1].[Details_Name] - FROM [Sample] AS [s1] - WHERE [s1].[Details_Name] IS NOT NULL -) AS [t0] ON [s].[UniqueNo] = [t0].[UniqueNo] WHERE [s].[UniqueNo] = 1", // - @"SELECT TOP(1) [s].[UniqueNo], [s].[MaxLengthProperty], [s].[Name], [s].[RowVersion], [t].[UniqueNo], [t].[AdditionalDetails_Name], [t0].[UniqueNo], [t0].[Details_Name] + @"SELECT TOP(1) [s].[UniqueNo], [s].[MaxLengthProperty], [s].[Name], [s].[RowVersion], [s].[AdditionalDetails_Name], [s].[Details_Name] FROM [Sample] AS [s] -LEFT JOIN ( - SELECT [s0].[UniqueNo], [s0].[AdditionalDetails_Name] - FROM [Sample] AS [s0] - WHERE [s0].[AdditionalDetails_Name] IS NOT NULL -) AS [t] ON [s].[UniqueNo] = [t].[UniqueNo] -LEFT JOIN ( - SELECT [s1].[UniqueNo], [s1].[Details_Name] - FROM [Sample] AS [s1] - WHERE [s1].[Details_Name] IS NOT NULL -) AS [t0] ON [s].[UniqueNo] = [t0].[UniqueNo] WHERE [s].[UniqueNo] = 1", // @"@p2='1' diff --git a/test/EFCore.SqlServer.FunctionalTests/PropertyEntrySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/PropertyEntrySqlServerTest.cs index 19a65080ecf..d83d4141bee 100644 --- a/test/EFCore.SqlServer.FunctionalTests/PropertyEntrySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/PropertyEntrySqlServerTest.cs @@ -18,13 +18,8 @@ public override void Property_entry_original_value_is_set() base.Property_entry_original_value_is_set(); AssertSql( - @"SELECT TOP(1) [e].[Id], [e].[EngineSupplierId], [e].[Name], [t].[Id], [t].[StorageLocation_Latitude], [t].[StorageLocation_Longitude] + @"SELECT TOP(1) [e].[Id], [e].[EngineSupplierId], [e].[Name], [e].[StorageLocation_Latitude], [e].[StorageLocation_Longitude] FROM [Engines] AS [e] -LEFT JOIN ( - SELECT [e0].[Id], [e0].[StorageLocation_Latitude], [e0].[StorageLocation_Longitude] - FROM [Engines] AS [e0] - WHERE [e0].[StorageLocation_Longitude] IS NOT NULL AND [e0].[StorageLocation_Latitude] IS NOT NULL -) AS [t] ON [e].[Id] = [t].[Id] ORDER BY [e].[Id]", // @"@p1='1' diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsWeakQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsWeakQuerySqlServerTest.cs index 01007af18aa..684ab4579eb 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsWeakQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsWeakQuerySqlServerTest.cs @@ -21,14 +21,8 @@ public override async Task Simple_level1_include(bool async) await base.Simple_level1_include(async); AssertSql( - @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] -FROM [Level1] AS [l] -LEFT JOIN ( - SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] - FROM [Level1] AS [l0] - INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] - WHERE [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l0].[Level1_Required_Id] IS NOT NULL AND [l0].[OneToOne_Required_PK_Date] IS NOT NULL) -) AS [t] ON [l].[Id] = [t].[Id]"); + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToOne_Required_PK_Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Level2_Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id] +FROM [Level1] AS [l]"); } public override async Task Simple_level1(bool async) @@ -45,25 +39,8 @@ public override async Task Simple_level1_level2_include(bool async) await base.Simple_level1_level2_include(async); AssertSql( - @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id] -FROM [Level1] AS [l] -LEFT JOIN ( - SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] - FROM [Level1] AS [l0] - INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] - WHERE [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l0].[Level1_Required_Id] IS NOT NULL AND [l0].[OneToOne_Required_PK_Date] IS NOT NULL) -) AS [t] ON [l].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id] AS [Id0], [t0].[Id0] AS [Id00] - FROM [Level1] AS [l2] - INNER JOIN ( - SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] - FROM [Level1] AS [l3] - INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] - WHERE [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t0] ON [l2].[Id] = [t0].[Id] - WHERE [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l2].[Level2_Required_Id] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id]"); + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToOne_Required_PK_Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Level2_Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[Level2_Optional_Id], [l].[Level2_Required_Id], [l].[Level3_Name], [l].[OneToMany_Optional_Inverse3Id], [l].[OneToMany_Required_Inverse3Id], [l].[OneToOne_Optional_PK_Inverse3Id] +FROM [Level1] AS [l]"); } public override async Task Simple_level1_level2_GroupBy_Count(bool async) @@ -73,24 +50,7 @@ public override async Task Simple_level1_level2_GroupBy_Count(bool async) AssertSql( @"SELECT COUNT(*) FROM [Level1] AS [l] -LEFT JOIN ( - SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] - FROM [Level1] AS [l0] - INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] - WHERE [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l0].[Level1_Required_Id] IS NOT NULL AND [l0].[OneToOne_Required_PK_Date] IS NOT NULL) -) AS [t] ON [l].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id] AS [Id0], [t0].[Id0] AS [Id00] - FROM [Level1] AS [l2] - INNER JOIN ( - SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] - FROM [Level1] AS [l3] - INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] - WHERE [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t0] ON [l2].[Id] = [t0].[Id] - WHERE [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l2].[Level2_Required_Id] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -GROUP BY [t1].[Level3_Name]"); +GROUP BY [l].[Level3_Name]"); } public override async Task Simple_level1_level2_GroupBy_Having_Count(bool async) @@ -100,25 +60,8 @@ public override async Task Simple_level1_level2_GroupBy_Having_Count(bool async) AssertSql( @"SELECT COUNT(*) FROM [Level1] AS [l] -LEFT JOIN ( - SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] - FROM [Level1] AS [l0] - INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] - WHERE [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l0].[Level1_Required_Id] IS NOT NULL AND [l0].[OneToOne_Required_PK_Date] IS NOT NULL) -) AS [t] ON [l].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id] AS [Id0], [t0].[Id0] AS [Id00] - FROM [Level1] AS [l2] - INNER JOIN ( - SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] - FROM [Level1] AS [l3] - INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] - WHERE [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t0] ON [l2].[Id] = [t0].[Id] - WHERE [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l2].[Level2_Required_Id] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -GROUP BY [t1].[Level3_Name] -HAVING MIN(COALESCE([t].[Id], 0)) > 0"); +GROUP BY [l].[Level3_Name] +HAVING MIN(COALESCE([l].[Id], 0)) > 0"); } public override async Task Simple_level1_level2_level3_include(bool async) @@ -126,41 +69,8 @@ public override async Task Simple_level1_level2_level3_include(bool async) await base.Simple_level1_level2_level3_include(async); AssertSql( - @"SELECT [l].[Id], [l].[Date], [l].[Name], [t].[Id], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id], [t1].[Id], [t1].[Level2_Optional_Id], [t1].[Level2_Required_Id], [t1].[Level3_Name], [t1].[OneToMany_Optional_Inverse3Id], [t1].[OneToMany_Required_Inverse3Id], [t1].[OneToOne_Optional_PK_Inverse3Id], [t4].[Id], [t4].[Level3_Optional_Id], [t4].[Level3_Required_Id], [t4].[Level4_Name], [t4].[OneToMany_Optional_Inverse4Id], [t4].[OneToMany_Required_Inverse4Id], [t4].[OneToOne_Optional_PK_Inverse4Id] -FROM [Level1] AS [l] -LEFT JOIN ( - SELECT [l0].[Id], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] - FROM [Level1] AS [l0] - INNER JOIN [Level1] AS [l1] ON [l0].[Id] = [l1].[Id] - WHERE [l0].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l0].[Level1_Required_Id] IS NOT NULL AND [l0].[OneToOne_Required_PK_Date] IS NOT NULL) -) AS [t] ON [l].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [l2].[Id], [l2].[Level2_Optional_Id], [l2].[Level2_Required_Id], [l2].[Level3_Name], [l2].[OneToMany_Optional_Inverse3Id], [l2].[OneToMany_Required_Inverse3Id], [l2].[OneToOne_Optional_PK_Inverse3Id], [t0].[Id] AS [Id0], [t0].[Id0] AS [Id00] - FROM [Level1] AS [l2] - INNER JOIN ( - SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] - FROM [Level1] AS [l3] - INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] - WHERE [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t0] ON [l2].[Id] = [t0].[Id] - WHERE [l2].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l2].[Level2_Required_Id] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [l5].[Id], [l5].[Level3_Optional_Id], [l5].[Level3_Required_Id], [l5].[Level4_Name], [l5].[OneToMany_Optional_Inverse4Id], [l5].[OneToMany_Required_Inverse4Id], [l5].[OneToOne_Optional_PK_Inverse4Id], [t3].[Id] AS [Id0], [t3].[Id0] AS [Id00], [t3].[Id00] AS [Id000] - FROM [Level1] AS [l5] - INNER JOIN ( - SELECT [l6].[Id], [l6].[Level2_Optional_Id], [l6].[Level2_Required_Id], [l6].[Level3_Name], [l6].[OneToMany_Optional_Inverse3Id], [l6].[OneToMany_Required_Inverse3Id], [l6].[OneToOne_Optional_PK_Inverse3Id], [t2].[Id] AS [Id0], [t2].[Id0] AS [Id00] - FROM [Level1] AS [l6] - INNER JOIN ( - SELECT [l7].[Id], [l7].[OneToOne_Required_PK_Date], [l7].[Level1_Optional_Id], [l7].[Level1_Required_Id], [l7].[Level2_Name], [l7].[OneToMany_Optional_Inverse2Id], [l7].[OneToMany_Required_Inverse2Id], [l7].[OneToOne_Optional_PK_Inverse2Id], [l8].[Id] AS [Id0] - FROM [Level1] AS [l7] - INNER JOIN [Level1] AS [l8] ON [l7].[Id] = [l8].[Id] - WHERE [l7].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l7].[Level1_Required_Id] IS NOT NULL AND [l7].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t2] ON [l6].[Id] = [t2].[Id] - WHERE [l6].[OneToMany_Required_Inverse3Id] IS NOT NULL AND [l6].[Level2_Required_Id] IS NOT NULL - ) AS [t3] ON [l5].[Id] = [t3].[Id] - WHERE [l5].[OneToMany_Required_Inverse4Id] IS NOT NULL AND [l5].[Level3_Required_Id] IS NOT NULL -) AS [t4] ON [t1].[Id] = [t4].[Id]"); + @"SELECT [l].[Id], [l].[Date], [l].[Name], [l].[OneToOne_Required_PK_Date], [l].[Level1_Optional_Id], [l].[Level1_Required_Id], [l].[Level2_Name], [l].[OneToMany_Optional_Inverse2Id], [l].[OneToMany_Required_Inverse2Id], [l].[OneToOne_Optional_PK_Inverse2Id], [l].[Level2_Optional_Id], [l].[Level2_Required_Id], [l].[Level3_Name], [l].[OneToMany_Optional_Inverse3Id], [l].[OneToMany_Required_Inverse3Id], [l].[OneToOne_Optional_PK_Inverse3Id], [l].[Level3_Optional_Id], [l].[Level3_Required_Id], [l].[Level4_Name], [l].[OneToMany_Optional_Inverse4Id], [l].[OneToMany_Required_Inverse4Id], [l].[OneToOne_Optional_PK_Inverse4Id] +FROM [Level1] AS [l]"); } public override async Task Nested_group_join_with_take(bool async) @@ -170,47 +80,21 @@ public override async Task Nested_group_join_with_take(bool async) AssertSql( @"@__p_0='2' -SELECT [t5].[Level2_Name] +SELECT [t1].[Level2_Name] FROM ( - SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [t0].[Id] AS [Id0], [t0].[Date] AS [Date0], [t0].[Name] AS [Name0] + SELECT TOP(@__p_0) [l].[Id], [l].[Date], [l].[Name], [t].[Id] AS [Id0], [t].[Date] AS [Date0], [t].[Name] AS [Name0], [t].[Id0] AS [Id00], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] FROM [Level1] AS [l] LEFT JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[Id] AS [Id0] FROM [Level1] AS [l0] - LEFT JOIN ( - SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] - FROM [Level1] AS [l1] - INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] - WHERE [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t] ON [l0].[Id] = [t].[Id] - WHERE [t].[Id] IS NOT NULL - ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] + ) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] ORDER BY [l].[Id] -) AS [t1] +) AS [t0] LEFT JOIN ( - SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] - FROM [Level1] AS [l3] - INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] - WHERE [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToOne_Required_PK_Date] IS NOT NULL) -) AS [t2] ON [t1].[Id0] = [t2].[Id] -LEFT JOIN ( - SELECT [l5].[Id], [l5].[Date], [l5].[Name], [t3].[Id] AS [Id0], [t3].[OneToOne_Required_PK_Date], [t3].[Level1_Optional_Id], [t3].[Level1_Required_Id], [t3].[Level2_Name], [t3].[OneToMany_Optional_Inverse2Id], [t3].[OneToMany_Required_Inverse2Id], [t3].[OneToOne_Optional_PK_Inverse2Id] - FROM [Level1] AS [l5] - LEFT JOIN ( - SELECT [l6].[Id], [l6].[OneToOne_Required_PK_Date], [l6].[Level1_Optional_Id], [l6].[Level1_Required_Id], [l6].[Level2_Name], [l6].[OneToMany_Optional_Inverse2Id], [l6].[OneToMany_Required_Inverse2Id], [l6].[OneToOne_Optional_PK_Inverse2Id], [l7].[Id] AS [Id0] - FROM [Level1] AS [l6] - INNER JOIN [Level1] AS [l7] ON [l6].[Id] = [l7].[Id] - WHERE [l6].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l6].[Level1_Required_Id] IS NOT NULL AND [l6].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t3] ON [l5].[Id] = [t3].[Id] - WHERE [t3].[Id] IS NOT NULL -) AS [t4] ON [t2].[Id] = [t4].[Level1_Optional_Id] -LEFT JOIN ( - SELECT [l8].[Id], [l8].[OneToOne_Required_PK_Date], [l8].[Level1_Optional_Id], [l8].[Level1_Required_Id], [l8].[Level2_Name], [l8].[OneToMany_Optional_Inverse2Id], [l8].[OneToMany_Required_Inverse2Id], [l8].[OneToOne_Optional_PK_Inverse2Id], [l9].[Id] AS [Id0] - FROM [Level1] AS [l8] - INNER JOIN [Level1] AS [l9] ON [l8].[Id] = [l9].[Id] - WHERE [l8].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l8].[Level1_Required_Id] IS NOT NULL AND [l8].[OneToOne_Required_PK_Date] IS NOT NULL) -) AS [t5] ON [t4].[Id] = [t5].[Id] -ORDER BY [t1].[Id]"); + SELECT [l1].[Id], [l1].[Date], [l1].[Name], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l1].[Id] AS [Id0] + FROM [Level1] AS [l1] +) AS [t1] ON [t0].[Id00] = [t1].[Level1_Optional_Id] +ORDER BY [t0].[Id]"); } public override async Task Explicit_GroupJoin_in_subquery_with_unrelated_projection2(bool async) @@ -218,29 +102,16 @@ public override async Task Explicit_GroupJoin_in_subquery_with_unrelated_project await base.Explicit_GroupJoin_in_subquery_with_unrelated_projection2(async); AssertSql( - @"SELECT [t2].[Id] + @"SELECT [t0].[Id] FROM ( SELECT DISTINCT [l].[Id], [l].[Date], [l].[Name] FROM [Level1] AS [l] LEFT JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[Id] AS [Id0] FROM [Level1] AS [l0] - LEFT JOIN ( - SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] - FROM [Level1] AS [l1] - INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] - WHERE [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t] ON [l0].[Id] = [t].[Id] - WHERE [t].[Id] IS NOT NULL - ) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] - LEFT JOIN ( - SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] - FROM [Level1] AS [l3] - INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] - WHERE [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t1] ON [t0].[Id] = [t1].[Id] - WHERE ([t1].[Level2_Name] <> N'Foo') OR [t1].[Level2_Name] IS NULL -) AS [t2]"); + ) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id] + WHERE ([t].[Level2_Name] <> N'Foo') OR [t].[Level2_Name] IS NULL +) AS [t0]"); } public override async Task Result_operator_nav_prop_reference_optional_via_DefaultIfEmpty(bool async) @@ -249,27 +120,14 @@ public override async Task Result_operator_nav_prop_reference_optional_via_Defau AssertSql( @"SELECT SUM(CASE - WHEN [t1].[Id] IS NULL THEN 0 - ELSE [t1].[Level1_Required_Id] + WHEN [t].[Id0] IS NULL THEN 0 + ELSE [t].[Level1_Required_Id] END) FROM [Level1] AS [l] LEFT JOIN ( - SELECT [l0].[Id], [l0].[Date], [l0].[Name], [t].[Id] AS [Id0], [t].[OneToOne_Required_PK_Date], [t].[Level1_Optional_Id], [t].[Level1_Required_Id], [t].[Level2_Name], [t].[OneToMany_Optional_Inverse2Id], [t].[OneToMany_Required_Inverse2Id], [t].[OneToOne_Optional_PK_Inverse2Id] + SELECT [l0].[Id], [l0].[Date], [l0].[Name], [l0].[OneToOne_Required_PK_Date], [l0].[Level1_Optional_Id], [l0].[Level1_Required_Id], [l0].[Level2_Name], [l0].[OneToMany_Optional_Inverse2Id], [l0].[OneToMany_Required_Inverse2Id], [l0].[OneToOne_Optional_PK_Inverse2Id], [l0].[Id] AS [Id0] FROM [Level1] AS [l0] - LEFT JOIN ( - SELECT [l1].[Id], [l1].[OneToOne_Required_PK_Date], [l1].[Level1_Optional_Id], [l1].[Level1_Required_Id], [l1].[Level2_Name], [l1].[OneToMany_Optional_Inverse2Id], [l1].[OneToMany_Required_Inverse2Id], [l1].[OneToOne_Optional_PK_Inverse2Id], [l2].[Id] AS [Id0] - FROM [Level1] AS [l1] - INNER JOIN [Level1] AS [l2] ON [l1].[Id] = [l2].[Id] - WHERE [l1].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l1].[Level1_Required_Id] IS NOT NULL AND [l1].[OneToOne_Required_PK_Date] IS NOT NULL) - ) AS [t] ON [l0].[Id] = [t].[Id] - WHERE [t].[Id] IS NOT NULL -) AS [t0] ON [l].[Id] = [t0].[Level1_Optional_Id] -LEFT JOIN ( - SELECT [l3].[Id], [l3].[OneToOne_Required_PK_Date], [l3].[Level1_Optional_Id], [l3].[Level1_Required_Id], [l3].[Level2_Name], [l3].[OneToMany_Optional_Inverse2Id], [l3].[OneToMany_Required_Inverse2Id], [l3].[OneToOne_Optional_PK_Inverse2Id], [l4].[Id] AS [Id0] - FROM [Level1] AS [l3] - INNER JOIN [Level1] AS [l4] ON [l3].[Id] = [l4].[Id] - WHERE [l3].[OneToMany_Required_Inverse2Id] IS NOT NULL AND ([l3].[Level1_Required_Id] IS NOT NULL AND [l3].[OneToOne_Required_PK_Date] IS NOT NULL) -) AS [t1] ON [t0].[Id] = [t1].[Id]"); +) AS [t] ON [l].[Id] = [t].[Level1_Optional_Id]"); } public override async Task SelectMany_with_Include1(bool async) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs index 354a5f55616..6da3fb01a62 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs @@ -1391,6 +1391,19 @@ FROM [Customers] AS [c] ORDER BY [c].[CustomerID]"); } + public override async Task Projecting_multiple_collection_with_same_constant_works(bool async) + { + await base.Projecting_multiple_collection_with_same_constant_works(async); + + AssertSql( + @"SELECT [c].[CustomerID], 1, [o].[OrderID], [o0].[OrderID] +FROM [Customers] AS [c] +LEFT JOIN [Orders] AS [o] ON [c].[CustomerID] = [o].[CustomerID] +LEFT JOIN [Orders] AS [o0] ON [c].[CustomerID] = [o0].[CustomerID] +WHERE [c].[CustomerID] = N'ALFKI' +ORDER BY [c].[CustomerID], [o].[OrderID], [o0].[OrderID]"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs index ce300e8761c..4bc3334d2a1 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs @@ -20,54 +20,16 @@ public override async Task Query_with_owned_entity_equality_operator(bool async) await base.Query_with_owned_entity_equality_operator(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t0].[Id], [t0].[PersonAddress_AddressLine], [t0].[PersonAddress_ZipCode], [t1].[Id], [t1].[PersonAddress_Country_Name], [t1].[PersonAddress_Country_PlanetId], [t3].[Id], [t4].[Id], [t4].[BranchAddress_Country_Name], [t4].[BranchAddress_Country_PlanetId], [t6].[Id], [t7].[Id], [t7].[LeafAAddress_Country_Name], [t7].[LeafAAddress_Country_PlanetId], [t].[Id], [o9].[ClientId], [o9].[Id], [o9].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[Id], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [t].[Id], [o1].[ClientId], [o1].[Id], [o1].[OrderDate] FROM [OwnedPerson] AS [o] CROSS JOIN ( SELECT [o0].[Id], [o0].[Discriminator], [o0].[Name] FROM [OwnedPerson] AS [o0] WHERE [o0].[Discriminator] = N'LeafB' ) AS [t] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL -) AS [t0] ON [o].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t1] ON [t0].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o3].[Id], [t2].[Id] AS [Id0] - FROM [OwnedPerson] AS [o3] - INNER JOIN ( - SELECT [o4].[Id], [o4].[Discriminator], [o4].[Name] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t2] ON [o3].[Id] = [t2].[Id] -) AS [t3] ON [o].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[BranchAddress_Country_Name], [o5].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t4] ON [t3].[Id] = [t4].[Id] -LEFT JOIN ( - SELECT [o6].[Id], [t5].[Id] AS [Id0] - FROM [OwnedPerson] AS [o6] - INNER JOIN ( - SELECT [o7].[Id], [o7].[Discriminator], [o7].[Name] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[Discriminator] = N'LeafA' - ) AS [t5] ON [o6].[Id] = [t5].[Id] -) AS [t6] ON [o].[Id] = [t6].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [o8].[LeafAAddress_Country_Name], [o8].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o8] - WHERE [o8].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t7] ON [t6].[Id] = [t7].[Id] -LEFT JOIN [Order] AS [o9] ON [o].[Id] = [o9].[ClientId] +LEFT JOIN [Order] AS [o1] ON [o].[Id] = [o1].[ClientId] WHERE 0 = 1 -ORDER BY [o].[Id], [t].[Id], [o9].[ClientId], [o9].[Id]"); +ORDER BY [o].[Id], [t].[Id], [o1].[ClientId], [o1].[Id]"); } public override async Task Query_for_base_type_loads_all_owned_navs(bool async) @@ -76,62 +38,10 @@ public override async Task Query_for_base_type_loads_all_owned_navs(bool async) // See issue #10067 AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafBAddress_Country_Name], [t6].[LeafBAddress_Country_PlanetId], [t8].[Id], [t9].[Id], [t9].[LeafAAddress_Country_Name], [t9].[LeafAAddress_Country_PlanetId], [o11].[ClientId], [o11].[Id], [o11].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafB' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafBAddress_Country_Name], [o7].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [t7].[Id] AS [Id0] - FROM [OwnedPerson] AS [o8] - INNER JOIN ( - SELECT [o9].[Id], [o9].[Discriminator], [o9].[Name] - FROM [OwnedPerson] AS [o9] - WHERE [o9].[Discriminator] = N'LeafA' - ) AS [t7] ON [o8].[Id] = [t7].[Id] -) AS [t8] ON [o].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o10].[Id], [o10].[LeafAAddress_Country_Name], [o10].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t9] ON [t8].[Id] = [t9].[Id] -LEFT JOIN [Order] AS [o11] ON [o].[Id] = [o11].[ClientId] -ORDER BY [o].[Id], [o11].[ClientId], [o11].[Id]"); +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task No_ignored_include_warning_when_implicit_load(bool async) @@ -148,49 +58,11 @@ public override async Task Query_for_branch_type_loads_all_owned_navs(bool async await base.Query_for_branch_type_loads_all_owned_navs(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafAAddress_Country_Name], [t6].[LeafAAddress_Country_PlanetId], [o8].[ClientId], [o8].[Id], [o8].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[Id], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafA' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafAAddress_Country_Name], [o7].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN [Order] AS [o8] ON [o].[Id] = [o8].[ClientId] +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Discriminator] IN (N'Branch', N'LeafA') -ORDER BY [o].[Id], [o8].[ClientId], [o8].[Id]"); +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Query_for_branch_type_loads_all_owned_navs_tracking(bool async) @@ -198,49 +70,11 @@ public override async Task Query_for_branch_type_loads_all_owned_navs_tracking(b await base.Query_for_branch_type_loads_all_owned_navs_tracking(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafAAddress_Country_Name], [t6].[LeafAAddress_Country_PlanetId], [o8].[ClientId], [o8].[Id], [o8].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[Id], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafA' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafAAddress_Country_Name], [o7].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN [Order] AS [o8] ON [o].[Id] = [o8].[ClientId] +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Discriminator] IN (N'Branch', N'LeafA') -ORDER BY [o].[Id], [o8].[ClientId], [o8].[Id]"); +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Query_for_leaf_type_loads_all_owned_navs(bool async) @@ -248,49 +82,11 @@ public override async Task Query_for_leaf_type_loads_all_owned_navs(bool async) await base.Query_for_leaf_type_loads_all_owned_navs(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafAAddress_Country_Name], [t6].[LeafAAddress_Country_PlanetId], [o8].[ClientId], [o8].[Id], [o8].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[Id], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafA' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafAAddress_Country_Name], [o7].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN [Order] AS [o8] ON [o].[Id] = [o8].[ClientId] +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Discriminator] = N'LeafA' -ORDER BY [o].[Id], [o8].[ClientId], [o8].[Id]"); +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Query_when_subquery(bool async) @@ -300,74 +96,17 @@ public override async Task Query_when_subquery(bool async) AssertSql( @"@__p_0='5' -SELECT [t0].[Id], [t0].[Discriminator], [t0].[Name], [t2].[Id], [t2].[PersonAddress_AddressLine], [t2].[PersonAddress_ZipCode], [t3].[Id], [t3].[PersonAddress_Country_Name], [t3].[PersonAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[BranchAddress_Country_Name], [t6].[BranchAddress_Country_PlanetId], [t8].[Id], [t9].[Id], [t9].[LeafBAddress_Country_Name], [t9].[LeafBAddress_Country_PlanetId], [t11].[Id], [t12].[Id], [t12].[LeafAAddress_Country_Name], [t12].[LeafAAddress_Country_PlanetId], [o12].[ClientId], [o12].[Id], [o12].[OrderDate] +SELECT [t0].[Id], [t0].[Discriminator], [t0].[Name], [t0].[PersonAddress_AddressLine], [t0].[PersonAddress_PlaceType], [t0].[PersonAddress_ZipCode], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t0].[BranchAddress_BranchName], [t0].[BranchAddress_PlaceType], [t0].[BranchAddress_Country_Name], [t0].[BranchAddress_Country_PlanetId], [t0].[LeafBAddress_LeafBType], [t0].[LeafBAddress_PlaceType], [t0].[Id0], [t0].[LeafBAddress_Country_Name], [t0].[LeafBAddress_Country_PlanetId], [t0].[LeafAAddress_LeafType], [t0].[LeafAAddress_PlaceType], [t0].[LeafAAddress_Country_Name], [t0].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM ( - SELECT TOP(@__p_0) [t].[Id], [t].[Discriminator], [t].[Name] + SELECT TOP(@__p_0) [t].[Id], [t].[Discriminator], [t].[Name], [t].[PersonAddress_AddressLine], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[PersonAddress_Country_Name], [t].[PersonAddress_Country_PlanetId], [t].[BranchAddress_BranchName], [t].[BranchAddress_PlaceType], [t].[BranchAddress_Country_Name], [t].[BranchAddress_Country_PlanetId], [t].[LeafBAddress_LeafBType], [t].[LeafBAddress_PlaceType], [t].[Id0], [t].[LeafBAddress_Country_Name], [t].[LeafBAddress_Country_PlanetId], [t].[LeafAAddress_LeafType], [t].[LeafAAddress_PlaceType], [t].[LeafAAddress_Country_Name], [t].[LeafAAddress_Country_PlanetId] FROM ( - SELECT DISTINCT [o].[Id], [o].[Discriminator], [o].[Name] + SELECT DISTINCT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id] AS [Id0], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] FROM [OwnedPerson] AS [o] ) AS [t] ORDER BY [t].[Id] ) AS [t0] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t1] ON [t0].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL -) AS [t2] ON [t0].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o3].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o3] - INNER JOIN ( - SELECT [o4].[Id], [o4].[Discriminator], [o4].[Name] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t4] ON [o3].[Id] = [t4].[Id] -) AS [t5] ON [t0].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[BranchAddress_Country_Name], [o5].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN ( - SELECT [o6].[Id], [t7].[Id] AS [Id0] - FROM [OwnedPerson] AS [o6] - INNER JOIN ( - SELECT [o7].[Id], [o7].[Discriminator], [o7].[Name] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[Discriminator] = N'LeafB' - ) AS [t7] ON [o6].[Id] = [t7].[Id] -) AS [t8] ON [t0].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [o8].[LeafBAddress_Country_Name], [o8].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o8] - WHERE [o8].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t9] ON [t8].[Id] = [t9].[Id] -LEFT JOIN ( - SELECT [o9].[Id], [t10].[Id] AS [Id0] - FROM [OwnedPerson] AS [o9] - INNER JOIN ( - SELECT [o10].[Id], [o10].[Discriminator], [o10].[Name] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[Discriminator] = N'LeafA' - ) AS [t10] ON [o9].[Id] = [t10].[Id] -) AS [t11] ON [t0].[Id] = [t11].[Id] -LEFT JOIN ( - SELECT [o11].[Id], [o11].[LeafAAddress_Country_Name], [o11].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o11] - WHERE [o11].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t12] ON [t11].[Id] = [t12].[Id] -LEFT JOIN [Order] AS [o12] ON [t0].[Id] = [o12].[ClientId] -ORDER BY [t0].[Id], [o12].[ClientId], [o12].[Id]"); +LEFT JOIN [Order] AS [o0] ON [t0].[Id] = [o0].[ClientId] +ORDER BY [t0].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Navigation_rewrite_on_owned_reference_projecting_scalar(bool async) @@ -375,19 +114,9 @@ public override async Task Navigation_rewrite_on_owned_reference_projecting_scal await base.Navigation_rewrite_on_owned_reference_projecting_scalar(async); AssertSql( - @"SELECT [t0].[PersonAddress_Country_Name] + @"SELECT [o].[PersonAddress_Country_Name] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -WHERE [t0].[PersonAddress_Country_Name] = N'USA'"); +WHERE [o].[PersonAddress_Country_Name] = N'USA'"); } public override async Task Navigation_rewrite_on_owned_reference_projecting_entity(bool async) @@ -395,63 +124,11 @@ public override async Task Navigation_rewrite_on_owned_reference_projecting_enti await base.Navigation_rewrite_on_owned_reference_projecting_entity(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafBAddress_Country_Name], [t6].[LeafBAddress_Country_PlanetId], [t8].[Id], [t9].[Id], [t9].[LeafAAddress_Country_Name], [t9].[LeafAAddress_Country_PlanetId], [o11].[ClientId], [o11].[Id], [o11].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafB' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafBAddress_Country_Name], [o7].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [t7].[Id] AS [Id0] - FROM [OwnedPerson] AS [o8] - INNER JOIN ( - SELECT [o9].[Id], [o9].[Discriminator], [o9].[Name] - FROM [OwnedPerson] AS [o9] - WHERE [o9].[Discriminator] = N'LeafA' - ) AS [t7] ON [o8].[Id] = [t7].[Id] -) AS [t8] ON [o].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o10].[Id], [o10].[LeafAAddress_Country_Name], [o10].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t9] ON [t8].[Id] = [t9].[Id] -LEFT JOIN [Order] AS [o11] ON [o].[Id] = [o11].[ClientId] -WHERE [t0].[PersonAddress_Country_Name] = N'USA' -ORDER BY [o].[Id], [o11].[ClientId], [o11].[Id]"); +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] +WHERE [o].[PersonAddress_Country_Name] = N'USA' +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Navigation_rewrite_on_owned_collection(bool async) @@ -492,22 +169,12 @@ public override async Task Navigation_rewrite_on_owned_collection_with_compositi AssertSql( @"SELECT ( - SELECT TOP(1) [t0].[PersonAddress_Country_Name] + SELECT TOP(1) [o0].[PersonAddress_Country_Name] FROM [Order] AS [o] LEFT JOIN [OwnedPerson] AS [o0] ON [o].[ClientId] = [o0].[Id] - LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL - ) AS [t] ON [o0].[Id] = [t].[Id] - LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL - ) AS [t0] ON [t].[Id] = [t0].[Id] - WHERE [o3].[Id] = [o].[ClientId] + WHERE [o1].[Id] = [o].[ClientId] ORDER BY [o].[Id]) -FROM [OwnedPerson] AS [o3]"); +FROM [OwnedPerson] AS [o1]"); } public override async Task SelectMany_on_owned_collection(bool async) @@ -527,17 +194,7 @@ public override async Task Navigation_rewrite_on_owned_reference_followed_by_reg AssertSql( @"SELECT [p].[Id], [p].[StarId] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id]"); +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id]"); } public override async Task Filter_owned_entity_chained_with_regular_entity_followed_by_projecting_owned_collection(bool async) @@ -545,22 +202,12 @@ public override async Task Filter_owned_entity_chained_with_regular_entity_follo await base.Filter_owned_entity_chained_with_regular_entity_followed_by_projecting_owned_collection(async); AssertSql( - @"SELECT [o].[Id], [o2].[ClientId], [o2].[Id], [o2].[OrderDate] + @"SELECT [o].[Id], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] -LEFT JOIN [Order] AS [o2] ON [o].[Id] = [o2].[ClientId] +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id] +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE ([p].[Id] <> 42) OR [p].[Id] IS NULL -ORDER BY [o].[Id], [o2].[ClientId], [o2].[Id]"); +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Project_multiple_owned_navigations(bool async) @@ -568,21 +215,11 @@ public override async Task Project_multiple_owned_navigations(bool async) await base.Project_multiple_owned_navigations(async); AssertSql( - @"SELECT [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [p].[Id], [p].[StarId], [o].[Id], [o2].[ClientId], [o2].[Id], [o2].[OrderDate] + @"SELECT [o].[Id], [o].[PersonAddress_AddressLine], [o].[PersonAddress_PlaceType], [o].[PersonAddress_ZipCode], [o].[PersonAddress_Country_Name], [o].[PersonAddress_Country_PlanetId], [p].[Id], [p].[StarId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] -LEFT JOIN [Order] AS [o2] ON [o].[Id] = [o2].[ClientId] -ORDER BY [o].[Id], [o2].[ClientId], [o2].[Id]"); +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id] +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Project_multiple_owned_navigations_with_expansion_on_owned_collections(bool async) @@ -590,36 +227,16 @@ public override async Task Project_multiple_owned_navigations_with_expansion_on_ await base.Project_multiple_owned_navigations_with_expansion_on_owned_collections(async); AssertSql( - @"SELECT ( + @"SELECT ( SELECT COUNT(*) FROM [Order] AS [o] LEFT JOIN [OwnedPerson] AS [o0] ON [o].[ClientId] = [o0].[Id] - LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL - ) AS [t] ON [o0].[Id] = [t].[Id] - LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL - ) AS [t0] ON [t].[Id] = [t0].[Id] - LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] + LEFT JOIN [Planet] AS [p] ON [o0].[PersonAddress_Country_PlanetId] = [p].[Id] LEFT JOIN [Star] AS [s] ON [p].[StarId] = [s].[Id] - WHERE ([o3].[Id] = [o].[ClientId]) AND (([s].[Id] <> 42) OR [s].[Id] IS NULL)) AS [Count], [p0].[Id], [p0].[StarId] -FROM [OwnedPerson] AS [o3] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[PersonAddress_AddressLine], [o4].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[PersonAddress_ZipCode] IS NOT NULL -) AS [t1] ON [o3].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[PersonAddress_Country_Name], [o5].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t2] ON [t1].[Id] = [t2].[Id] -LEFT JOIN [Planet] AS [p0] ON [t2].[PersonAddress_Country_PlanetId] = [p0].[Id] -ORDER BY [o3].[Id]"); + WHERE ([o1].[Id] = [o].[ClientId]) AND (([s].[Id] <> 42) OR [s].[Id] IS NULL)) AS [Count], [p0].[Id], [p0].[StarId] +FROM [OwnedPerson] AS [o1] +LEFT JOIN [Planet] AS [p0] ON [o1].[PersonAddress_Country_PlanetId] = [p0].[Id] +ORDER BY [o1].[Id]"); } public override async Task Navigation_rewrite_on_owned_reference_followed_by_regular_entity_filter(bool async) @@ -627,64 +244,12 @@ public override async Task Navigation_rewrite_on_owned_reference_followed_by_reg await base.Navigation_rewrite_on_owned_reference_followed_by_regular_entity_filter(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafBAddress_Country_Name], [t6].[LeafBAddress_Country_PlanetId], [t8].[Id], [t9].[Id], [t9].[LeafAAddress_Country_Name], [t9].[LeafAAddress_Country_PlanetId], [o11].[ClientId], [o11].[Id], [o11].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafB' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafBAddress_Country_Name], [o7].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [t7].[Id] AS [Id0] - FROM [OwnedPerson] AS [o8] - INNER JOIN ( - SELECT [o9].[Id], [o9].[Discriminator], [o9].[Name] - FROM [OwnedPerson] AS [o9] - WHERE [o9].[Discriminator] = N'LeafA' - ) AS [t7] ON [o8].[Id] = [t7].[Id] -) AS [t8] ON [o].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o10].[Id], [o10].[LeafAAddress_Country_Name], [o10].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t9] ON [t8].[Id] = [t9].[Id] -LEFT JOIN [Order] AS [o11] ON [o].[Id] = [o11].[ClientId] +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id] +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE ([p].[Id] <> 7) OR [p].[Id] IS NULL -ORDER BY [o].[Id], [o11].[ClientId], [o11].[Id]"); +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Navigation_rewrite_on_owned_reference_followed_by_regular_entity_and_property(bool async) @@ -694,17 +259,7 @@ public override async Task Navigation_rewrite_on_owned_reference_followed_by_reg AssertSql( @"SELECT [p].[Id] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id]"); +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id]"); } public override async Task Navigation_rewrite_on_owned_reference_followed_by_regular_entity_and_collection(bool async) @@ -714,17 +269,7 @@ public override async Task Navigation_rewrite_on_owned_reference_followed_by_reg AssertSql( @"SELECT [o].[Id], [m].[Id], [m].[Diameter], [m].[PlanetId] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id] LEFT JOIN [Moon] AS [m] ON [p].[Id] = [m].[PlanetId] ORDER BY [o].[Id], [m].[Id]"); } @@ -736,17 +281,7 @@ public override async Task SelectMany_on_owned_reference_followed_by_regular_ent AssertSql( @"SELECT [m].[Id], [m].[Diameter], [m].[PlanetId] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id] INNER JOIN [Moon] AS [m] ON [p].[Id] = [m].[PlanetId]"); } @@ -757,17 +292,7 @@ public override async Task SelectMany_on_owned_reference_with_entity_in_between_ AssertSql( @"SELECT [e].[Id], [e].[Name], [e].[StarId] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id] LEFT JOIN [Star] AS [s] ON [p].[StarId] = [s].[Id] INNER JOIN [Element] AS [e] ON [s].[Id] = [e].[StarId]"); } @@ -779,17 +304,7 @@ public override async Task Navigation_rewrite_on_owned_reference_followed_by_reg AssertSql( @"SELECT [s].[Id], [s].[Name], [o].[Id], [e].[Id], [e].[Name], [e].[StarId] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id] LEFT JOIN [Star] AS [s] ON [p].[StarId] = [s].[Id] LEFT JOIN [Element] AS [e] ON [s].[Id] = [e].[StarId] ORDER BY [o].[Id], [e].[Id]"); @@ -803,17 +318,7 @@ public override async Task Navigation_rewrite_on_owned_reference_followed_by_reg AssertSql( @"SELECT [s].[Name] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id] LEFT JOIN [Star] AS [s] ON [p].[StarId] = [s].[Id]"); } @@ -826,17 +331,7 @@ await base.Navigation_rewrite_on_owned_reference_followed_by_regular_entity_and_ AssertSql( @"SELECT [s].[Id], [s].[Name], [o].[Id], [e].[Id], [e].[Name], [e].[StarId] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN [Planet] AS [p] ON [t0].[PersonAddress_Country_PlanetId] = [p].[Id] +LEFT JOIN [Planet] AS [p] ON [o].[PersonAddress_Country_PlanetId] = [p].[Id] LEFT JOIN [Star] AS [s] ON [p].[StarId] = [s].[Id] LEFT JOIN [Element] AS [e] ON [s].[Id] = [e].[StarId] WHERE [s].[Name] = N'Sol' @@ -848,49 +343,11 @@ public override async Task Query_with_OfType_eagerly_loads_correct_owned_navigat await base.Query_with_OfType_eagerly_loads_correct_owned_navigations(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafAAddress_Country_Name], [t6].[LeafAAddress_Country_PlanetId], [o8].[ClientId], [o8].[Id], [o8].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[Id], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafA' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafAAddress_Country_Name], [o7].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN [Order] AS [o8] ON [o].[Id] = [o8].[ClientId] +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Discriminator] = N'LeafA' -ORDER BY [o].[Id], [o8].[ClientId], [o8].[Id]"); +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Preserve_includes_when_applying_skip_take_after_anonymous_type_select(bool async) @@ -904,72 +361,15 @@ public override async Task Preserve_includes_when_applying_skip_take_after_anony @"@__p_1='0' @__p_2='100' -SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t1].[Id], [t1].[PersonAddress_AddressLine], [t1].[PersonAddress_ZipCode], [t2].[Id], [t2].[PersonAddress_Country_Name], [t2].[PersonAddress_Country_PlanetId], [t4].[Id], [t5].[Id], [t5].[BranchAddress_Country_Name], [t5].[BranchAddress_Country_PlanetId], [t7].[Id], [t8].[Id], [t8].[LeafBAddress_Country_Name], [t8].[LeafBAddress_Country_PlanetId], [t10].[Id], [t11].[Id], [t11].[LeafAAddress_Country_Name], [t11].[LeafAAddress_Country_PlanetId], [o12].[ClientId], [o12].[Id], [o12].[OrderDate] +SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t].[PersonAddress_AddressLine], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[PersonAddress_Country_Name], [t].[PersonAddress_Country_PlanetId], [t].[BranchAddress_BranchName], [t].[BranchAddress_PlaceType], [t].[BranchAddress_Country_Name], [t].[BranchAddress_Country_PlanetId], [t].[LeafBAddress_LeafBType], [t].[LeafBAddress_PlaceType], [t].[Id0], [t].[LeafBAddress_Country_Name], [t].[LeafBAddress_Country_PlanetId], [t].[LeafAAddress_LeafType], [t].[LeafAAddress_PlaceType], [t].[LeafAAddress_Country_Name], [t].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM ( - SELECT [o].[Id], [o].[Discriminator], [o].[Name] + SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id] AS [Id0], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] FROM [OwnedPerson] AS [o] ORDER BY [o].[Id] OFFSET @__p_1 ROWS FETCH NEXT @__p_2 ROWS ONLY ) AS [t] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t2] ON [t1].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o3].[Id], [t3].[Id] AS [Id0] - FROM [OwnedPerson] AS [o3] - INNER JOIN ( - SELECT [o4].[Id], [o4].[Discriminator], [o4].[Name] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t3] ON [o3].[Id] = [t3].[Id] -) AS [t4] ON [t].[Id] = [t4].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[BranchAddress_Country_Name], [o5].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t5] ON [t4].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o6].[Id], [t6].[Id] AS [Id0] - FROM [OwnedPerson] AS [o6] - INNER JOIN ( - SELECT [o7].[Id], [o7].[Discriminator], [o7].[Name] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[Discriminator] = N'LeafB' - ) AS [t6] ON [o6].[Id] = [t6].[Id] -) AS [t7] ON [t].[Id] = [t7].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [o8].[LeafBAddress_Country_Name], [o8].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o8] - WHERE [o8].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t8] ON [t7].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o9].[Id], [t9].[Id] AS [Id0] - FROM [OwnedPerson] AS [o9] - INNER JOIN ( - SELECT [o10].[Id], [o10].[Discriminator], [o10].[Name] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[Discriminator] = N'LeafA' - ) AS [t9] ON [o9].[Id] = [t9].[Id] -) AS [t10] ON [t].[Id] = [t10].[Id] -LEFT JOIN ( - SELECT [o11].[Id], [o11].[LeafAAddress_Country_Name], [o11].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o11] - WHERE [o11].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t11] ON [t10].[Id] = [t11].[Id] -LEFT JOIN [Order] AS [o12] ON [t].[Id] = [o12].[ClientId] -ORDER BY [t].[Id], [o12].[ClientId], [o12].[Id]"); +LEFT JOIN [Order] AS [o0] ON [t].[Id] = [o0].[ClientId] +ORDER BY [t].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Unmapped_property_projection_loads_owned_navigations(bool async) @@ -977,63 +377,11 @@ public override async Task Unmapped_property_projection_loads_owned_navigations( await base.Unmapped_property_projection_loads_owned_navigations(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafBAddress_Country_Name], [t6].[LeafBAddress_Country_PlanetId], [t8].[Id], [t9].[Id], [t9].[LeafAAddress_Country_Name], [t9].[LeafAAddress_Country_PlanetId], [o11].[ClientId], [o11].[Id], [o11].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafB' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafBAddress_Country_Name], [o7].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [t7].[Id] AS [Id0] - FROM [OwnedPerson] AS [o8] - INNER JOIN ( - SELECT [o9].[Id], [o9].[Discriminator], [o9].[Name] - FROM [OwnedPerson] AS [o9] - WHERE [o9].[Discriminator] = N'LeafA' - ) AS [t7] ON [o8].[Id] = [t7].[Id] -) AS [t8] ON [o].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o10].[Id], [o10].[LeafAAddress_Country_Name], [o10].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t9] ON [t8].[Id] = [t9].[Id] -LEFT JOIN [Order] AS [o11] ON [o].[Id] = [o11].[ClientId] +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Id] = 1 -ORDER BY [o].[Id], [o11].[ClientId], [o11].[Id]"); +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Client_method_skip_loads_owned_navigations(bool async) @@ -1043,72 +391,15 @@ public override async Task Client_method_skip_loads_owned_navigations(bool async AssertSql( @"@__p_0='1' -SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t1].[Id], [t1].[PersonAddress_AddressLine], [t1].[PersonAddress_ZipCode], [t2].[Id], [t2].[PersonAddress_Country_Name], [t2].[PersonAddress_Country_PlanetId], [t4].[Id], [t5].[Id], [t5].[BranchAddress_Country_Name], [t5].[BranchAddress_Country_PlanetId], [t7].[Id], [t8].[Id], [t8].[LeafBAddress_Country_Name], [t8].[LeafBAddress_Country_PlanetId], [t10].[Id], [t11].[Id], [t11].[LeafAAddress_Country_Name], [t11].[LeafAAddress_Country_PlanetId], [o12].[ClientId], [o12].[Id], [o12].[OrderDate] +SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t].[PersonAddress_AddressLine], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[PersonAddress_Country_Name], [t].[PersonAddress_Country_PlanetId], [t].[BranchAddress_BranchName], [t].[BranchAddress_PlaceType], [t].[BranchAddress_Country_Name], [t].[BranchAddress_Country_PlanetId], [t].[LeafBAddress_LeafBType], [t].[LeafBAddress_PlaceType], [t].[Id0], [t].[LeafBAddress_Country_Name], [t].[LeafBAddress_Country_PlanetId], [t].[LeafAAddress_LeafType], [t].[LeafAAddress_PlaceType], [t].[LeafAAddress_Country_Name], [t].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM ( - SELECT [o].[Id], [o].[Discriminator], [o].[Name] + SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id] AS [Id0], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] FROM [OwnedPerson] AS [o] ORDER BY [o].[Id] OFFSET @__p_0 ROWS ) AS [t] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t2] ON [t1].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o3].[Id], [t3].[Id] AS [Id0] - FROM [OwnedPerson] AS [o3] - INNER JOIN ( - SELECT [o4].[Id], [o4].[Discriminator], [o4].[Name] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t3] ON [o3].[Id] = [t3].[Id] -) AS [t4] ON [t].[Id] = [t4].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[BranchAddress_Country_Name], [o5].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t5] ON [t4].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o6].[Id], [t6].[Id] AS [Id0] - FROM [OwnedPerson] AS [o6] - INNER JOIN ( - SELECT [o7].[Id], [o7].[Discriminator], [o7].[Name] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[Discriminator] = N'LeafB' - ) AS [t6] ON [o6].[Id] = [t6].[Id] -) AS [t7] ON [t].[Id] = [t7].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [o8].[LeafBAddress_Country_Name], [o8].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o8] - WHERE [o8].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t8] ON [t7].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o9].[Id], [t9].[Id] AS [Id0] - FROM [OwnedPerson] AS [o9] - INNER JOIN ( - SELECT [o10].[Id], [o10].[Discriminator], [o10].[Name] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[Discriminator] = N'LeafA' - ) AS [t9] ON [o9].[Id] = [t9].[Id] -) AS [t10] ON [t].[Id] = [t10].[Id] -LEFT JOIN ( - SELECT [o11].[Id], [o11].[LeafAAddress_Country_Name], [o11].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o11] - WHERE [o11].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t11] ON [t10].[Id] = [t11].[Id] -LEFT JOIN [Order] AS [o12] ON [t].[Id] = [o12].[ClientId] -ORDER BY [t].[Id], [o12].[ClientId], [o12].[Id]"); +LEFT JOIN [Order] AS [o0] ON [t].[Id] = [o0].[ClientId] +ORDER BY [t].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Client_method_take_loads_owned_navigations(bool async) @@ -1118,71 +409,14 @@ public override async Task Client_method_take_loads_owned_navigations(bool async AssertSql( @"@__p_0='2' -SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t1].[Id], [t1].[PersonAddress_AddressLine], [t1].[PersonAddress_ZipCode], [t2].[Id], [t2].[PersonAddress_Country_Name], [t2].[PersonAddress_Country_PlanetId], [t4].[Id], [t5].[Id], [t5].[BranchAddress_Country_Name], [t5].[BranchAddress_Country_PlanetId], [t7].[Id], [t8].[Id], [t8].[LeafBAddress_Country_Name], [t8].[LeafBAddress_Country_PlanetId], [t10].[Id], [t11].[Id], [t11].[LeafAAddress_Country_Name], [t11].[LeafAAddress_Country_PlanetId], [o12].[ClientId], [o12].[Id], [o12].[OrderDate] +SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t].[PersonAddress_AddressLine], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[PersonAddress_Country_Name], [t].[PersonAddress_Country_PlanetId], [t].[BranchAddress_BranchName], [t].[BranchAddress_PlaceType], [t].[BranchAddress_Country_Name], [t].[BranchAddress_Country_PlanetId], [t].[LeafBAddress_LeafBType], [t].[LeafBAddress_PlaceType], [t].[Id0], [t].[LeafBAddress_Country_Name], [t].[LeafBAddress_Country_PlanetId], [t].[LeafAAddress_LeafType], [t].[LeafAAddress_PlaceType], [t].[LeafAAddress_Country_Name], [t].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM ( - SELECT TOP(@__p_0) [o].[Id], [o].[Discriminator], [o].[Name] + SELECT TOP(@__p_0) [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id] AS [Id0], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] FROM [OwnedPerson] AS [o] ORDER BY [o].[Id] ) AS [t] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t2] ON [t1].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o3].[Id], [t3].[Id] AS [Id0] - FROM [OwnedPerson] AS [o3] - INNER JOIN ( - SELECT [o4].[Id], [o4].[Discriminator], [o4].[Name] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t3] ON [o3].[Id] = [t3].[Id] -) AS [t4] ON [t].[Id] = [t4].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[BranchAddress_Country_Name], [o5].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t5] ON [t4].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o6].[Id], [t6].[Id] AS [Id0] - FROM [OwnedPerson] AS [o6] - INNER JOIN ( - SELECT [o7].[Id], [o7].[Discriminator], [o7].[Name] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[Discriminator] = N'LeafB' - ) AS [t6] ON [o6].[Id] = [t6].[Id] -) AS [t7] ON [t].[Id] = [t7].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [o8].[LeafBAddress_Country_Name], [o8].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o8] - WHERE [o8].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t8] ON [t7].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o9].[Id], [t9].[Id] AS [Id0] - FROM [OwnedPerson] AS [o9] - INNER JOIN ( - SELECT [o10].[Id], [o10].[Discriminator], [o10].[Name] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[Discriminator] = N'LeafA' - ) AS [t9] ON [o9].[Id] = [t9].[Id] -) AS [t10] ON [t].[Id] = [t10].[Id] -LEFT JOIN ( - SELECT [o11].[Id], [o11].[LeafAAddress_Country_Name], [o11].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o11] - WHERE [o11].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t11] ON [t10].[Id] = [t11].[Id] -LEFT JOIN [Order] AS [o12] ON [t].[Id] = [o12].[ClientId] -ORDER BY [t].[Id], [o12].[ClientId], [o12].[Id]"); +LEFT JOIN [Order] AS [o0] ON [t].[Id] = [o0].[ClientId] +ORDER BY [t].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Client_method_skip_take_loads_owned_navigations(bool async) @@ -1193,72 +427,15 @@ public override async Task Client_method_skip_take_loads_owned_navigations(bool @"@__p_0='1' @__p_1='2' -SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t1].[Id], [t1].[PersonAddress_AddressLine], [t1].[PersonAddress_ZipCode], [t2].[Id], [t2].[PersonAddress_Country_Name], [t2].[PersonAddress_Country_PlanetId], [t4].[Id], [t5].[Id], [t5].[BranchAddress_Country_Name], [t5].[BranchAddress_Country_PlanetId], [t7].[Id], [t8].[Id], [t8].[LeafBAddress_Country_Name], [t8].[LeafBAddress_Country_PlanetId], [t10].[Id], [t11].[Id], [t11].[LeafAAddress_Country_Name], [t11].[LeafAAddress_Country_PlanetId], [o12].[ClientId], [o12].[Id], [o12].[OrderDate] +SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t].[PersonAddress_AddressLine], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[PersonAddress_Country_Name], [t].[PersonAddress_Country_PlanetId], [t].[BranchAddress_BranchName], [t].[BranchAddress_PlaceType], [t].[BranchAddress_Country_Name], [t].[BranchAddress_Country_PlanetId], [t].[LeafBAddress_LeafBType], [t].[LeafBAddress_PlaceType], [t].[Id0], [t].[LeafBAddress_Country_Name], [t].[LeafBAddress_Country_PlanetId], [t].[LeafAAddress_LeafType], [t].[LeafAAddress_PlaceType], [t].[LeafAAddress_Country_Name], [t].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM ( - SELECT [o].[Id], [o].[Discriminator], [o].[Name] + SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id] AS [Id0], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] FROM [OwnedPerson] AS [o] ORDER BY [o].[Id] OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY ) AS [t] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t2] ON [t1].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o3].[Id], [t3].[Id] AS [Id0] - FROM [OwnedPerson] AS [o3] - INNER JOIN ( - SELECT [o4].[Id], [o4].[Discriminator], [o4].[Name] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t3] ON [o3].[Id] = [t3].[Id] -) AS [t4] ON [t].[Id] = [t4].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[BranchAddress_Country_Name], [o5].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t5] ON [t4].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o6].[Id], [t6].[Id] AS [Id0] - FROM [OwnedPerson] AS [o6] - INNER JOIN ( - SELECT [o7].[Id], [o7].[Discriminator], [o7].[Name] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[Discriminator] = N'LeafB' - ) AS [t6] ON [o6].[Id] = [t6].[Id] -) AS [t7] ON [t].[Id] = [t7].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [o8].[LeafBAddress_Country_Name], [o8].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o8] - WHERE [o8].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t8] ON [t7].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o9].[Id], [t9].[Id] AS [Id0] - FROM [OwnedPerson] AS [o9] - INNER JOIN ( - SELECT [o10].[Id], [o10].[Discriminator], [o10].[Name] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[Discriminator] = N'LeafA' - ) AS [t9] ON [o9].[Id] = [t9].[Id] -) AS [t10] ON [t].[Id] = [t10].[Id] -LEFT JOIN ( - SELECT [o11].[Id], [o11].[LeafAAddress_Country_Name], [o11].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o11] - WHERE [o11].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t11] ON [t10].[Id] = [t11].[Id] -LEFT JOIN [Order] AS [o12] ON [t].[Id] = [o12].[ClientId] -ORDER BY [t].[Id], [o12].[ClientId], [o12].[Id]"); +LEFT JOIN [Order] AS [o0] ON [t].[Id] = [o0].[ClientId] +ORDER BY [t].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Client_method_skip_loads_owned_navigations_variation_2(bool async) @@ -1268,72 +445,15 @@ public override async Task Client_method_skip_loads_owned_navigations_variation_ AssertSql( @"@__p_0='1' -SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t1].[Id], [t1].[PersonAddress_AddressLine], [t1].[PersonAddress_ZipCode], [t2].[Id], [t2].[PersonAddress_Country_Name], [t2].[PersonAddress_Country_PlanetId], [t4].[Id], [t5].[Id], [t5].[BranchAddress_Country_Name], [t5].[BranchAddress_Country_PlanetId], [t7].[Id], [t8].[Id], [t8].[LeafBAddress_Country_Name], [t8].[LeafBAddress_Country_PlanetId], [t10].[Id], [t11].[Id], [t11].[LeafAAddress_Country_Name], [t11].[LeafAAddress_Country_PlanetId], [o12].[ClientId], [o12].[Id], [o12].[OrderDate] +SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t].[PersonAddress_AddressLine], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[PersonAddress_Country_Name], [t].[PersonAddress_Country_PlanetId], [t].[BranchAddress_BranchName], [t].[BranchAddress_PlaceType], [t].[BranchAddress_Country_Name], [t].[BranchAddress_Country_PlanetId], [t].[LeafBAddress_LeafBType], [t].[LeafBAddress_PlaceType], [t].[Id0], [t].[LeafBAddress_Country_Name], [t].[LeafBAddress_Country_PlanetId], [t].[LeafAAddress_LeafType], [t].[LeafAAddress_PlaceType], [t].[LeafAAddress_Country_Name], [t].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM ( - SELECT [o].[Id], [o].[Discriminator], [o].[Name] + SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id] AS [Id0], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] FROM [OwnedPerson] AS [o] ORDER BY [o].[Id] OFFSET @__p_0 ROWS ) AS [t] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t2] ON [t1].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o3].[Id], [t3].[Id] AS [Id0] - FROM [OwnedPerson] AS [o3] - INNER JOIN ( - SELECT [o4].[Id], [o4].[Discriminator], [o4].[Name] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t3] ON [o3].[Id] = [t3].[Id] -) AS [t4] ON [t].[Id] = [t4].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[BranchAddress_Country_Name], [o5].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t5] ON [t4].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o6].[Id], [t6].[Id] AS [Id0] - FROM [OwnedPerson] AS [o6] - INNER JOIN ( - SELECT [o7].[Id], [o7].[Discriminator], [o7].[Name] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[Discriminator] = N'LeafB' - ) AS [t6] ON [o6].[Id] = [t6].[Id] -) AS [t7] ON [t].[Id] = [t7].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [o8].[LeafBAddress_Country_Name], [o8].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o8] - WHERE [o8].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t8] ON [t7].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o9].[Id], [t9].[Id] AS [Id0] - FROM [OwnedPerson] AS [o9] - INNER JOIN ( - SELECT [o10].[Id], [o10].[Discriminator], [o10].[Name] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[Discriminator] = N'LeafA' - ) AS [t9] ON [o9].[Id] = [t9].[Id] -) AS [t10] ON [t].[Id] = [t10].[Id] -LEFT JOIN ( - SELECT [o11].[Id], [o11].[LeafAAddress_Country_Name], [o11].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o11] - WHERE [o11].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t11] ON [t10].[Id] = [t11].[Id] -LEFT JOIN [Order] AS [o12] ON [t].[Id] = [o12].[ClientId] -ORDER BY [t].[Id], [o12].[ClientId], [o12].[Id]"); +LEFT JOIN [Order] AS [o0] ON [t].[Id] = [o0].[ClientId] +ORDER BY [t].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Client_method_take_loads_owned_navigations_variation_2(bool async) @@ -1343,71 +463,14 @@ public override async Task Client_method_take_loads_owned_navigations_variation_ AssertSql( @"@__p_0='2' -SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t1].[Id], [t1].[PersonAddress_AddressLine], [t1].[PersonAddress_ZipCode], [t2].[Id], [t2].[PersonAddress_Country_Name], [t2].[PersonAddress_Country_PlanetId], [t4].[Id], [t5].[Id], [t5].[BranchAddress_Country_Name], [t5].[BranchAddress_Country_PlanetId], [t7].[Id], [t8].[Id], [t8].[LeafBAddress_Country_Name], [t8].[LeafBAddress_Country_PlanetId], [t10].[Id], [t11].[Id], [t11].[LeafAAddress_Country_Name], [t11].[LeafAAddress_Country_PlanetId], [o12].[ClientId], [o12].[Id], [o12].[OrderDate] +SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t].[PersonAddress_AddressLine], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[PersonAddress_Country_Name], [t].[PersonAddress_Country_PlanetId], [t].[BranchAddress_BranchName], [t].[BranchAddress_PlaceType], [t].[BranchAddress_Country_Name], [t].[BranchAddress_Country_PlanetId], [t].[LeafBAddress_LeafBType], [t].[LeafBAddress_PlaceType], [t].[Id0], [t].[LeafBAddress_Country_Name], [t].[LeafBAddress_Country_PlanetId], [t].[LeafAAddress_LeafType], [t].[LeafAAddress_PlaceType], [t].[LeafAAddress_Country_Name], [t].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM ( - SELECT TOP(@__p_0) [o].[Id], [o].[Discriminator], [o].[Name] + SELECT TOP(@__p_0) [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id] AS [Id0], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] FROM [OwnedPerson] AS [o] ORDER BY [o].[Id] ) AS [t] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t2] ON [t1].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o3].[Id], [t3].[Id] AS [Id0] - FROM [OwnedPerson] AS [o3] - INNER JOIN ( - SELECT [o4].[Id], [o4].[Discriminator], [o4].[Name] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t3] ON [o3].[Id] = [t3].[Id] -) AS [t4] ON [t].[Id] = [t4].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[BranchAddress_Country_Name], [o5].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t5] ON [t4].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o6].[Id], [t6].[Id] AS [Id0] - FROM [OwnedPerson] AS [o6] - INNER JOIN ( - SELECT [o7].[Id], [o7].[Discriminator], [o7].[Name] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[Discriminator] = N'LeafB' - ) AS [t6] ON [o6].[Id] = [t6].[Id] -) AS [t7] ON [t].[Id] = [t7].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [o8].[LeafBAddress_Country_Name], [o8].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o8] - WHERE [o8].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t8] ON [t7].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o9].[Id], [t9].[Id] AS [Id0] - FROM [OwnedPerson] AS [o9] - INNER JOIN ( - SELECT [o10].[Id], [o10].[Discriminator], [o10].[Name] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[Discriminator] = N'LeafA' - ) AS [t9] ON [o9].[Id] = [t9].[Id] -) AS [t10] ON [t].[Id] = [t10].[Id] -LEFT JOIN ( - SELECT [o11].[Id], [o11].[LeafAAddress_Country_Name], [o11].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o11] - WHERE [o11].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t11] ON [t10].[Id] = [t11].[Id] -LEFT JOIN [Order] AS [o12] ON [t].[Id] = [o12].[ClientId] -ORDER BY [t].[Id], [o12].[ClientId], [o12].[Id]"); +LEFT JOIN [Order] AS [o0] ON [t].[Id] = [o0].[ClientId] +ORDER BY [t].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Client_method_skip_take_loads_owned_navigations_variation_2(bool async) @@ -1418,72 +481,15 @@ public override async Task Client_method_skip_take_loads_owned_navigations_varia @"@__p_0='1' @__p_1='2' -SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t1].[Id], [t1].[PersonAddress_AddressLine], [t1].[PersonAddress_ZipCode], [t2].[Id], [t2].[PersonAddress_Country_Name], [t2].[PersonAddress_Country_PlanetId], [t4].[Id], [t5].[Id], [t5].[BranchAddress_Country_Name], [t5].[BranchAddress_Country_PlanetId], [t7].[Id], [t8].[Id], [t8].[LeafBAddress_Country_Name], [t8].[LeafBAddress_Country_PlanetId], [t10].[Id], [t11].[Id], [t11].[LeafAAddress_Country_Name], [t11].[LeafAAddress_Country_PlanetId], [o12].[ClientId], [o12].[Id], [o12].[OrderDate] +SELECT [t].[Id], [t].[Discriminator], [t].[Name], [t].[PersonAddress_AddressLine], [t].[PersonAddress_PlaceType], [t].[PersonAddress_ZipCode], [t].[PersonAddress_Country_Name], [t].[PersonAddress_Country_PlanetId], [t].[BranchAddress_BranchName], [t].[BranchAddress_PlaceType], [t].[BranchAddress_Country_Name], [t].[BranchAddress_Country_PlanetId], [t].[LeafBAddress_LeafBType], [t].[LeafBAddress_PlaceType], [t].[Id0], [t].[LeafBAddress_Country_Name], [t].[LeafBAddress_Country_PlanetId], [t].[LeafAAddress_LeafType], [t].[LeafAAddress_PlaceType], [t].[LeafAAddress_Country_Name], [t].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM ( - SELECT [o].[Id], [o].[Discriminator], [o].[Name] + SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id] AS [Id0], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] FROM [OwnedPerson] AS [o] ORDER BY [o].[Id] OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY ) AS [t] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_AddressLine], [o1].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_ZipCode] IS NOT NULL -) AS [t1] ON [t].[Id] = [t1].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_Country_Name], [o2].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t2] ON [t1].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o3].[Id], [t3].[Id] AS [Id0] - FROM [OwnedPerson] AS [o3] - INNER JOIN ( - SELECT [o4].[Id], [o4].[Discriminator], [o4].[Name] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t3] ON [o3].[Id] = [t3].[Id] -) AS [t4] ON [t].[Id] = [t4].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [o5].[BranchAddress_Country_Name], [o5].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o5] - WHERE [o5].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t5] ON [t4].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o6].[Id], [t6].[Id] AS [Id0] - FROM [OwnedPerson] AS [o6] - INNER JOIN ( - SELECT [o7].[Id], [o7].[Discriminator], [o7].[Name] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[Discriminator] = N'LeafB' - ) AS [t6] ON [o6].[Id] = [t6].[Id] -) AS [t7] ON [t].[Id] = [t7].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [o8].[LeafBAddress_Country_Name], [o8].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o8] - WHERE [o8].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t8] ON [t7].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o9].[Id], [t9].[Id] AS [Id0] - FROM [OwnedPerson] AS [o9] - INNER JOIN ( - SELECT [o10].[Id], [o10].[Discriminator], [o10].[Name] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[Discriminator] = N'LeafA' - ) AS [t9] ON [o9].[Id] = [t9].[Id] -) AS [t10] ON [t].[Id] = [t10].[Id] -LEFT JOIN ( - SELECT [o11].[Id], [o11].[LeafAAddress_Country_Name], [o11].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o11] - WHERE [o11].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t11] ON [t10].[Id] = [t11].[Id] -LEFT JOIN [Order] AS [o12] ON [t].[Id] = [o12].[ClientId] -ORDER BY [t].[Id], [o12].[ClientId], [o12].[Id]"); +LEFT JOIN [Order] AS [o0] ON [t].[Id] = [o0].[ClientId] +ORDER BY [t].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Where_owned_collection_navigation_ToList_Count(bool async) @@ -1558,63 +564,11 @@ public override async Task Can_query_on_indexer_properties(bool async) await base.Can_query_on_indexer_properties(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafBAddress_Country_Name], [t6].[LeafBAddress_Country_PlanetId], [t8].[Id], [t9].[Id], [t9].[LeafAAddress_Country_Name], [t9].[LeafAAddress_Country_PlanetId], [o11].[ClientId], [o11].[Id], [o11].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafB' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafBAddress_Country_Name], [o7].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [t7].[Id] AS [Id0] - FROM [OwnedPerson] AS [o8] - INNER JOIN ( - SELECT [o9].[Id], [o9].[Discriminator], [o9].[Name] - FROM [OwnedPerson] AS [o9] - WHERE [o9].[Discriminator] = N'LeafA' - ) AS [t7] ON [o8].[Id] = [t7].[Id] -) AS [t8] ON [o].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o10].[Id], [o10].[LeafAAddress_Country_Name], [o10].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t9] ON [t8].[Id] = [t9].[Id] -LEFT JOIN [Order] AS [o11] ON [o].[Id] = [o11].[ClientId] +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] WHERE [o].[Name] = N'Mona Cy' -ORDER BY [o].[Id], [o11].[ClientId], [o11].[Id]"); +ORDER BY [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Can_query_on_owned_indexer_properties(bool async) @@ -1624,12 +578,7 @@ public override async Task Can_query_on_owned_indexer_properties(bool async) AssertSql( @"SELECT [o].[Name] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -WHERE [t].[PersonAddress_ZipCode] = 38654"); +WHERE [o].[PersonAddress_ZipCode] = 38654"); } public override async Task Can_query_on_indexer_property_when_property_name_from_closure(bool async) @@ -1656,13 +605,8 @@ public override async Task Can_project_owned_indexer_properties(bool async) await base.Can_project_owned_indexer_properties(async); AssertSql( - @"SELECT [t].[PersonAddress_AddressLine] -FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id]"); + @"SELECT [o].[PersonAddress_AddressLine] +FROM [OwnedPerson] AS [o]"); } public override async Task Can_project_indexer_properties_converted(bool async) @@ -1679,13 +623,8 @@ public override async Task Can_project_owned_indexer_properties_converted(bool a await base.Can_project_owned_indexer_properties_converted(async); AssertSql( - @"SELECT [t].[PersonAddress_AddressLine] -FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id]"); + @"SELECT [o].[PersonAddress_AddressLine] +FROM [OwnedPerson] AS [o]"); } public override async Task Can_OrderBy_indexer_properties(bool async) @@ -1693,62 +632,10 @@ public override async Task Can_OrderBy_indexer_properties(bool async) await base.Can_OrderBy_indexer_properties(async); AssertSql( - @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[Id], [t].[PersonAddress_AddressLine], [t].[PersonAddress_ZipCode], [t0].[Id], [t0].[PersonAddress_Country_Name], [t0].[PersonAddress_Country_PlanetId], [t2].[Id], [t3].[Id], [t3].[BranchAddress_Country_Name], [t3].[BranchAddress_Country_PlanetId], [t5].[Id], [t6].[Id], [t6].[LeafBAddress_Country_Name], [t6].[LeafBAddress_Country_PlanetId], [t8].[Id], [t9].[Id], [t9].[LeafAAddress_Country_Name], [t9].[LeafAAddress_Country_PlanetId], [o11].[ClientId], [o11].[Id], [o11].[OrderDate] + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [o].[PersonAddress_AddressLine], [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].[Id], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId], [o0].[ClientId], [o0].[Id], [o0].[OrderDate] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [o1].[Id], [o1].[PersonAddress_Country_Name], [o1].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o1] - WHERE [o1].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t0] ON [t].[Id] = [t0].[Id] -LEFT JOIN ( - SELECT [o2].[Id], [t1].[Id] AS [Id0] - FROM [OwnedPerson] AS [o2] - INNER JOIN ( - SELECT [o3].[Id], [o3].[Discriminator], [o3].[Name] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[Discriminator] IN (N'Branch', N'LeafA') - ) AS [t1] ON [o2].[Id] = [t1].[Id] -) AS [t2] ON [o].[Id] = [t2].[Id] -LEFT JOIN ( - SELECT [o4].[Id], [o4].[BranchAddress_Country_Name], [o4].[BranchAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o4] - WHERE [o4].[BranchAddress_Country_PlanetId] IS NOT NULL -) AS [t3] ON [t2].[Id] = [t3].[Id] -LEFT JOIN ( - SELECT [o5].[Id], [t4].[Id] AS [Id0] - FROM [OwnedPerson] AS [o5] - INNER JOIN ( - SELECT [o6].[Id], [o6].[Discriminator], [o6].[Name] - FROM [OwnedPerson] AS [o6] - WHERE [o6].[Discriminator] = N'LeafB' - ) AS [t4] ON [o5].[Id] = [t4].[Id] -) AS [t5] ON [o].[Id] = [t5].[Id] -LEFT JOIN ( - SELECT [o7].[Id], [o7].[LeafBAddress_Country_Name], [o7].[LeafBAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o7] - WHERE [o7].[LeafBAddress_Country_PlanetId] IS NOT NULL -) AS [t6] ON [t5].[Id] = [t6].[Id] -LEFT JOIN ( - SELECT [o8].[Id], [t7].[Id] AS [Id0] - FROM [OwnedPerson] AS [o8] - INNER JOIN ( - SELECT [o9].[Id], [o9].[Discriminator], [o9].[Name] - FROM [OwnedPerson] AS [o9] - WHERE [o9].[Discriminator] = N'LeafA' - ) AS [t7] ON [o8].[Id] = [t7].[Id] -) AS [t8] ON [o].[Id] = [t8].[Id] -LEFT JOIN ( - SELECT [o10].[Id], [o10].[LeafAAddress_Country_Name], [o10].[LeafAAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o10] - WHERE [o10].[LeafAAddress_Country_PlanetId] IS NOT NULL -) AS [t9] ON [t8].[Id] = [t9].[Id] -LEFT JOIN [Order] AS [o11] ON [o].[Id] = [o11].[ClientId] -ORDER BY [o].[Name], [o].[Id], [o11].[ClientId], [o11].[Id]"); +LEFT JOIN [Order] AS [o0] ON [o].[Id] = [o0].[ClientId] +ORDER BY [o].[Name], [o].[Id], [o0].[ClientId], [o0].[Id]"); } public override async Task Can_OrderBy_indexer_properties_converted(bool async) @@ -1768,12 +655,7 @@ public override async Task Can_OrderBy_owned_indexer_properties(bool async) AssertSql( @"SELECT [o].[Name] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -ORDER BY [t].[PersonAddress_ZipCode], [o].[Id]"); +ORDER BY [o].[PersonAddress_ZipCode], [o].[Id]"); } public override async Task Can_OrderBy_owened_indexer_properties_converted(bool async) @@ -1783,12 +665,7 @@ public override async Task Can_OrderBy_owened_indexer_properties_converted(bool AssertSql( @"SELECT [o].[Name] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -ORDER BY [t].[PersonAddress_ZipCode], [o].[Id]"); +ORDER BY [o].[PersonAddress_ZipCode], [o].[Id]"); } public override async Task Can_group_by_indexer_property(bool isAsync) @@ -1818,12 +695,7 @@ public override async Task Can_group_by_owned_indexer_property(bool isAsync) AssertSql( @"SELECT COUNT(*) FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -GROUP BY [t].[PersonAddress_ZipCode]"); +GROUP BY [o].[PersonAddress_ZipCode]"); } public override async Task Can_group_by_converted_owned_indexer_property(bool isAsync) @@ -1833,12 +705,7 @@ public override async Task Can_group_by_converted_owned_indexer_property(bool is AssertSql( @"SELECT COUNT(*) FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -GROUP BY [t].[PersonAddress_ZipCode]"); +GROUP BY [o].[PersonAddress_ZipCode]"); } public override async Task Can_join_on_indexer_property_on_query(bool isAsync) @@ -1846,27 +713,9 @@ public override async Task Can_join_on_indexer_property_on_query(bool isAsync) await base.Can_join_on_indexer_property_on_query(isAsync); AssertSql( - @"SELECT [o].[Id], [t2].[PersonAddress_Country_Name] AS [Name] + @"SELECT [o].[Id], [o0].[PersonAddress_Country_Name] AS [Name] FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id] -INNER JOIN ( - SELECT [o1].[Id], [o1].[Discriminator], [o1].[Name], [t0].[Id] AS [Id0], [t0].[PersonAddress_AddressLine], [t0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o1] - LEFT JOIN ( - SELECT [o2].[Id], [o2].[PersonAddress_AddressLine], [o2].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o2] - WHERE [o2].[PersonAddress_ZipCode] IS NOT NULL - ) AS [t0] ON [o1].[Id] = [t0].[Id] -) AS [t1] ON [t].[PersonAddress_ZipCode] = [t1].[PersonAddress_ZipCode] -LEFT JOIN ( - SELECT [o3].[Id], [o3].[PersonAddress_Country_Name], [o3].[PersonAddress_Country_PlanetId] - FROM [OwnedPerson] AS [o3] - WHERE [o3].[PersonAddress_Country_PlanetId] IS NOT NULL -) AS [t2] ON [t1].[Id0] = [t2].[Id]"); +INNER JOIN [OwnedPerson] AS [o0] ON [o].[PersonAddress_ZipCode] = [o0].[PersonAddress_ZipCode]"); } public override async Task Projecting_indexer_property_ignores_include(bool isAsync) @@ -1874,13 +723,8 @@ public override async Task Projecting_indexer_property_ignores_include(bool isAs await base.Projecting_indexer_property_ignores_include(isAsync); AssertSql( - @"SELECT [t].[PersonAddress_ZipCode] AS [Nation] -FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id]"); + @"SELECT [o].[PersonAddress_ZipCode] AS [Nation] +FROM [OwnedPerson] AS [o]"); } public override async Task Projecting_indexer_property_ignores_include_converted(bool isAsync) @@ -1888,13 +732,8 @@ public override async Task Projecting_indexer_property_ignores_include_converted await base.Projecting_indexer_property_ignores_include_converted(isAsync); AssertSql( - @"SELECT [t].[PersonAddress_ZipCode] AS [Nation] -FROM [OwnedPerson] AS [o] -LEFT JOIN ( - SELECT [o0].[Id], [o0].[PersonAddress_AddressLine], [o0].[PersonAddress_ZipCode] - FROM [OwnedPerson] AS [o0] - WHERE [o0].[PersonAddress_ZipCode] IS NOT NULL -) AS [t] ON [o].[Id] = [t].[Id]"); + @"SELECT [o].[PersonAddress_ZipCode] AS [Nation] +FROM [OwnedPerson] AS [o]"); } public override async Task Indexer_property_is_pushdown_into_subquery(bool isAsync) @@ -1924,7 +763,7 @@ FROM [Order] AS [o0] } private void AssertSql(params string[] expected) - => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); + => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); public class OwnedQuerySqlServerFixture : RelationalOwnedQueryFixture { diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs index 7b62be29fe4..8bb83b5b233 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/QueryBugsTest.cs @@ -2289,23 +2289,10 @@ public void Include_collection_for_entity_with_owned_type_works() Assert.True(result[0].Cast.All(a => a.Details != null)); AssertSql( - @"SELECT [m].[Id], [m].[Title], [t].[Id], [t].[Details_Info], [t1].[Id], [t1].[Movie9202Id], [t1].[Name], [t1].[Id0], [t1].[Details_Info] + @"SELECT [m].[Id], [m].[Title], [m].[Details_Info], [a].[Id], [a].[Movie9202Id], [a].[Name], [a].[Details_Info] FROM [Movies] AS [m] -LEFT JOIN ( - SELECT [m0].[Id], [m0].[Details_Info] - FROM [Movies] AS [m0] - WHERE [m0].[Details_Info] IS NOT NULL -) AS [t] ON [m].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [a].[Id], [a].[Movie9202Id], [a].[Name], [t0].[Id] AS [Id0], [t0].[Details_Info] - FROM [Actors] AS [a] - LEFT JOIN ( - SELECT [a0].[Id], [a0].[Details_Info] - FROM [Actors] AS [a0] - WHERE [a0].[Details_Info] IS NOT NULL - ) AS [t0] ON [a].[Id] = [t0].[Id] -) AS [t1] ON [m].[Id] = [t1].[Movie9202Id] -ORDER BY [m].[Id], [t1].[Id]"); +LEFT JOIN [Actors] AS [a] ON [m].[Id] = [a].[Movie9202Id] +ORDER BY [m].[Id], [a].[Id]"); } } @@ -2324,23 +2311,10 @@ public void Include_collection_for_entity_with_owned_type_works_string() Assert.True(result[0].Cast.All(a => a.Details != null)); AssertSql( - @"SELECT [m].[Id], [m].[Title], [t].[Id], [t].[Details_Info], [t1].[Id], [t1].[Movie9202Id], [t1].[Name], [t1].[Id0], [t1].[Details_Info] + @"SELECT [m].[Id], [m].[Title], [m].[Details_Info], [a].[Id], [a].[Movie9202Id], [a].[Name], [a].[Details_Info] FROM [Movies] AS [m] -LEFT JOIN ( - SELECT [m0].[Id], [m0].[Details_Info] - FROM [Movies] AS [m0] - WHERE [m0].[Details_Info] IS NOT NULL -) AS [t] ON [m].[Id] = [t].[Id] -LEFT JOIN ( - SELECT [a].[Id], [a].[Movie9202Id], [a].[Name], [t0].[Id] AS [Id0], [t0].[Details_Info] - FROM [Actors] AS [a] - LEFT JOIN ( - SELECT [a0].[Id], [a0].[Details_Info] - FROM [Actors] AS [a0] - WHERE [a0].[Details_Info] IS NOT NULL - ) AS [t0] ON [a].[Id] = [t0].[Id] -) AS [t1] ON [m].[Id] = [t1].[Movie9202Id] -ORDER BY [m].[Id], [t1].[Id]"); +LEFT JOIN [Actors] AS [a] ON [m].[Id] = [a].[Movie9202Id] +ORDER BY [m].[Id], [a].[Id]"); } } @@ -4303,7 +4277,7 @@ private enum TodoType #region Bug13157 - [ConditionalFact] + [ConditionalFact(Skip = "Issue#20342")] public virtual void Correlated_subquery_with_owned_navigation_being_compared_to_null_works() { using (CreateDatabase13157()) @@ -4323,26 +4297,22 @@ public virtual void Correlated_subquery_with_owned_navigation_being_compared_to_ }).ToList(); Assert.Single(partners); - Assert.Single(partners[0].Addresses); - Assert.NotNull(partners[0].Addresses[0].Turnovers); - Assert.Equal(10, partners[0].Addresses[0].Turnovers.AmountIn); + Assert.Collection(partners[0].Addresses, + t => + { + Assert.NotNull(t.Turnovers); + Assert.Equal(10, t.Turnovers.AmountIn); + }, + t => + { + Assert.Null(t.Turnovers); + }); - AssertSql( - @"SELECT [p].[Id], [t0].[c], [t0].[Turnovers_AmountIn], [t0].[Id] + AssertSql( + @"SELECT [p].[Id], CAST(0 AS bit), [a].[Turnovers_AmountIn], [a].[Id] FROM [Partners] AS [p] -LEFT JOIN ( - SELECT CASE - WHEN [t].[Id] IS NULL THEN CAST(1 AS bit) - ELSE CAST(0 AS bit) - END AS [c], [t].[Turnovers_AmountIn], [a].[Id], [a].[Partner13157Id] - FROM [Address13157] AS [a] - LEFT JOIN ( - SELECT [a0].[Id], [a0].[Turnovers_AmountIn] - FROM [Address13157] AS [a0] - WHERE [a0].[Turnovers_AmountIn] IS NOT NULL - ) AS [t] ON [a].[Id] = [t].[Id] -) AS [t0] ON [p].[Id] = [t0].[Partner13157Id] -ORDER BY [p].[Id], [t0].[Id]"); +LEFT JOIN [Address13157] AS [a] ON [p].[Id] = [a].[Partner13157Id] +ORDER BY [p].[Id], [a].[Id]"); } } @@ -4357,7 +4327,8 @@ private SqlServerTestStore CreateDatabase13157() { Addresses = new List { - new Address13157 { Turnovers = new AddressTurnovers13157 { AmountIn = 10 } } + new Address13157 { Turnovers = new AddressTurnovers13157 { AmountIn = 10 } }, + new Address13157 { Turnovers = null }, } } ); @@ -5421,13 +5392,8 @@ public virtual void Expression_tree_constructed_via_interface_works_17276() var query = List17276(context.RemovableEntities); AssertSql( - @"SELECT [r].[Id], [r].[IsRemoved], [r].[Removed], [r].[RemovedByUser], [t].[Id], [t].[OwnedEntity_OwnedValue] + @"SELECT [r].[Id], [r].[IsRemoved], [r].[Removed], [r].[RemovedByUser], [r].[OwnedEntity_OwnedValue] FROM [RemovableEntities] AS [r] -LEFT JOIN ( - SELECT [r0].[Id], [r0].[OwnedEntity_OwnedValue] - FROM [RemovableEntities] AS [r0] - WHERE [r0].[OwnedEntity_OwnedValue] IS NOT NULL -) AS [t] ON [r].[Id] = [t].[Id] WHERE [r].[IsRemoved] <> CAST(1 AS bit)"); } } @@ -5461,14 +5427,9 @@ public virtual void Expression_tree_constructed_via_interface_for_owned_navigati .ToList(); AssertSql( - @"SELECT [r].[Id], [r].[IsRemoved], [r].[Removed], [r].[RemovedByUser], [t].[Id], [t].[OwnedEntity_OwnedValue] + @"SELECT [r].[Id], [r].[IsRemoved], [r].[Removed], [r].[RemovedByUser], [r].[OwnedEntity_OwnedValue] FROM [RemovableEntities] AS [r] -LEFT JOIN ( - SELECT [r0].[Id], [r0].[OwnedEntity_OwnedValue] - FROM [RemovableEntities] AS [r0] - WHERE [r0].[OwnedEntity_OwnedValue] IS NOT NULL -) AS [t] ON [r].[Id] = [t].[Id] -WHERE [t].[OwnedEntity_OwnedValue] = N'Abc'"); +WHERE [r].[OwnedEntity_OwnedValue] = N'Abc'"); } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/UdfDbFunctionSqlServerTests.cs b/test/EFCore.SqlServer.FunctionalTests/Query/UdfDbFunctionSqlServerTests.cs index eebde15230d..5ad4f8a43a1 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/UdfDbFunctionSqlServerTests.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/UdfDbFunctionSqlServerTests.cs @@ -696,14 +696,9 @@ public override void QF_OuterApply_Correlated_Select_Entity() base.QF_OuterApply_Correlated_Select_Entity(); AssertSql( - @"SELECT [c].[Id], [c].[FirstName], [c].[LastName], [t].[Id], [t].[CreditCard_CreditCardType], [t].[CreditCard_Number], [p].[CustomerId], [p].[Id], [p].[Number], [p].[PhoneType] + @"SELECT [c].[Id], [c].[FirstName], [c].[LastName], [c].[CreditCard_CreditCardType], [c].[CreditCard_Number], [p].[CustomerId], [p].[Id], [p].[Number], [p].[PhoneType] FROM [Customers] AS [c] OUTER APPLY [dbo].[GetCustomerOrderCountByYear]([c].[Id]) AS [o] -LEFT JOIN ( - SELECT [c0].[Id], [c0].[CreditCard_CreditCardType], [c0].[CreditCard_Number] - FROM [Customers] AS [c0] - WHERE [c0].[CreditCard_CreditCardType] IS NOT NULL -) AS [t] ON [c].[Id] = [t].[Id] LEFT JOIN [PhoneInformation] AS [p] ON [c].[Id] = [p].[CustomerId] WHERE [o].[Year] = 2000 ORDER BY [c].[Id], [o].[Year], [p].[CustomerId], [p].[Id]"); @@ -773,14 +768,9 @@ public override void QF_Owned_Many_Tracked_Select_Owned() base.QF_Owned_Many_Tracked_Select_Owned(); AssertSql( - @"SELECT [c].[Id], [c].[FirstName], [c].[LastName], [t].[Id], [t].[CreditCard_CreditCardType], [t].[CreditCard_Number], [p].[CustomerId], [p].[Id], [p0].[CustomerId], [p0].[Id], [p0].[Number], [p0].[PhoneType] + @"SELECT [c].[Id], [c].[FirstName], [c].[LastName], [c].[CreditCard_CreditCardType], [c].[CreditCard_Number], [p].[CustomerId], [p].[Id], [p0].[CustomerId], [p0].[Id], [p0].[Number], [p0].[PhoneType] FROM [Customers] AS [c] CROSS APPLY [dbo].[GetPhoneInformation]([c].[Id], N'234') AS [p] -LEFT JOIN ( - SELECT [c0].[Id], [c0].[CreditCard_CreditCardType], [c0].[CreditCard_Number] - FROM [Customers] AS [c0] - WHERE [c0].[CreditCard_CreditCardType] IS NOT NULL -) AS [t] ON [c].[Id] = [t].[Id] LEFT JOIN [PhoneInformation] AS [p0] ON [c].[Id] = [p0].[CustomerId] ORDER BY [c].[Id], [p].[CustomerId], [p].[Id], [p0].[CustomerId], [p0].[Id]"); } @@ -805,18 +795,13 @@ public override void QF_Owned_One_Tracked() base.QF_Owned_One_Tracked(); AssertSql( - @"SELECT [c].[Id], [c].[FirstName], [c].[LastName], [t0].[Id], [t0].[CreditCard_CreditCardType], [t0].[CreditCard_Number], [t].[Id], [t].[CreditCard_CreditCardType], [t].[CreditCard_Number], [p].[CustomerId], [p].[Id], [p].[Number], [p].[PhoneType] + @"SELECT [c].[Id], [c].[FirstName], [c].[LastName], [c].[CreditCard_CreditCardType], [c].[CreditCard_Number], [t].[Id], [t].[CreditCard_CreditCardType], [t].[CreditCard_Number], [p].[CustomerId], [p].[Id], [p].[Number], [p].[PhoneType] FROM [Customers] AS [c] CROSS APPLY ( SELECT [c0].[Id], [c0].[CreditCard_CreditCardType], [c0].[CreditCard_Number] FROM [dbo].[GetCreditCards]([c].[Id]) AS [c0] WHERE [c0].[CreditCard_CreditCardType] IS NOT NULL ) AS [t] -LEFT JOIN ( - SELECT [c1].[Id], [c1].[CreditCard_CreditCardType], [c1].[CreditCard_Number] - FROM [Customers] AS [c1] - WHERE [c1].[CreditCard_CreditCardType] IS NOT NULL -) AS [t0] ON [c].[Id] = [t0].[Id] LEFT JOIN [PhoneInformation] AS [p] ON [c].[Id] = [p].[CustomerId] ORDER BY [t].[CreditCard_Number], [c].[Id], [t].[Id], [p].[CustomerId], [p].[Id]"); } diff --git a/test/EFCore.Sqlite.FunctionalTests/DataAnnotationSqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/DataAnnotationSqliteTest.cs index b9e6fbca162..a0f0adf92f0 100644 --- a/test/EFCore.Sqlite.FunctionalTests/DataAnnotationSqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/DataAnnotationSqliteTest.cs @@ -97,33 +97,13 @@ public override void ConcurrencyCheckAttribute_throws_if_value_in_database_chang base.ConcurrencyCheckAttribute_throws_if_value_in_database_changed(); AssertSql( - @"SELECT ""s"".""UniqueNo"", ""s"".""MaxLengthProperty"", ""s"".""Name"", ""s"".""RowVersion"", ""t"".""UniqueNo"", ""t"".""AdditionalDetails_Name"", ""t0"".""UniqueNo"", ""t0"".""Details_Name"" + @"SELECT ""s"".""UniqueNo"", ""s"".""MaxLengthProperty"", ""s"".""Name"", ""s"".""RowVersion"", ""s"".""AdditionalDetails_Name"", ""s"".""Details_Name"" FROM ""Sample"" AS ""s"" -LEFT JOIN ( - SELECT ""s0"".""UniqueNo"", ""s0"".""AdditionalDetails_Name"" - FROM ""Sample"" AS ""s0"" - WHERE ""s0"".""AdditionalDetails_Name"" IS NOT NULL -) AS ""t"" ON ""s"".""UniqueNo"" = ""t"".""UniqueNo"" -LEFT JOIN ( - SELECT ""s1"".""UniqueNo"", ""s1"".""Details_Name"" - FROM ""Sample"" AS ""s1"" - WHERE ""s1"".""Details_Name"" IS NOT NULL -) AS ""t0"" ON ""s"".""UniqueNo"" = ""t0"".""UniqueNo"" WHERE ""s"".""UniqueNo"" = 1 LIMIT 1", // - @"SELECT ""s"".""UniqueNo"", ""s"".""MaxLengthProperty"", ""s"".""Name"", ""s"".""RowVersion"", ""t"".""UniqueNo"", ""t"".""AdditionalDetails_Name"", ""t0"".""UniqueNo"", ""t0"".""Details_Name"" + @"SELECT ""s"".""UniqueNo"", ""s"".""MaxLengthProperty"", ""s"".""Name"", ""s"".""RowVersion"", ""s"".""AdditionalDetails_Name"", ""s"".""Details_Name"" FROM ""Sample"" AS ""s"" -LEFT JOIN ( - SELECT ""s0"".""UniqueNo"", ""s0"".""AdditionalDetails_Name"" - FROM ""Sample"" AS ""s0"" - WHERE ""s0"".""AdditionalDetails_Name"" IS NOT NULL -) AS ""t"" ON ""s"".""UniqueNo"" = ""t"".""UniqueNo"" -LEFT JOIN ( - SELECT ""s1"".""UniqueNo"", ""s1"".""Details_Name"" - FROM ""Sample"" AS ""s1"" - WHERE ""s1"".""Details_Name"" IS NOT NULL -) AS ""t0"" ON ""s"".""UniqueNo"" = ""t0"".""UniqueNo"" WHERE ""s"".""UniqueNo"" = 1 LIMIT 1", // diff --git a/test/EFCore.Sqlite.FunctionalTests/PropertyEntrySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/PropertyEntrySqliteTest.cs index 7cce89b7d89..cd6318cd6f1 100644 --- a/test/EFCore.Sqlite.FunctionalTests/PropertyEntrySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/PropertyEntrySqliteTest.cs @@ -16,13 +16,8 @@ public override void Property_entry_original_value_is_set() base.Property_entry_original_value_is_set(); AssertSql( - @"SELECT ""e"".""Id"", ""e"".""EngineSupplierId"", ""e"".""Name"", ""t"".""Id"", ""t"".""StorageLocation_Latitude"", ""t"".""StorageLocation_Longitude"" + @"SELECT ""e"".""Id"", ""e"".""EngineSupplierId"", ""e"".""Name"", ""e"".""StorageLocation_Latitude"", ""e"".""StorageLocation_Longitude"" FROM ""Engines"" AS ""e"" -LEFT JOIN ( - SELECT ""e0"".""Id"", ""e0"".""StorageLocation_Latitude"", ""e0"".""StorageLocation_Longitude"" - FROM ""Engines"" AS ""e0"" - WHERE ""e0"".""StorageLocation_Longitude"" IS NOT NULL AND ""e0"".""StorageLocation_Latitude"" IS NOT NULL -) AS ""t"" ON ""e"".""Id"" = ""t"".""Id"" ORDER BY ""e"".""Id"" LIMIT 1", //