From 2385f0b6fcb7171c35ecbe20bb86e47415e96404 Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Thu, 19 Nov 2020 15:47:20 -0800 Subject: [PATCH] Cosmos: Apply projection in post processor --- .../CosmosQueryTranslationPostprocessor.cs | 8 ++++++++ .../CosmosShapedQueryCompilingExpressionVisitor.cs | 2 -- .../CustomConvertersTestBase.cs | 2 +- .../LazyLoadProxyTestBase.cs | 2 ++ .../OptimisticConcurrencyTestBase.cs | 12 ++++-------- .../StoreGeneratedTestBase.cs | 2 +- .../LazyLoadProxySqlServerTest.cs | 14 +++++++++----- .../ChangeTracking/Internal/QueryFixupTest.cs | 8 +++++--- 8 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryTranslationPostprocessor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryTranslationPostprocessor.cs index 9e35accddd3..0df9592314f 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryTranslationPostprocessor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryTranslationPostprocessor.cs @@ -46,6 +46,14 @@ public CosmosQueryTranslationPostprocessor( public override Expression Process(Expression query) { query = base.Process(query); + + if (query is ShapedQueryExpression shapedQueryExpression + && shapedQueryExpression.QueryExpression is SelectExpression selectExpression) + { + // Cosmos does not have nested select expression so this should be safe. + selectExpression.ApplyProjection(); + } + query = new CosmosValueConverterCompensatingExpressionVisitor(_sqlExpressionFactory).Visit(query); return query; diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs index 07a56d4df39..d9c7daf1b14 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.cs @@ -62,8 +62,6 @@ protected override Expression VisitShapedQuery(ShapedQueryExpression shapedQuery { case SelectExpression selectExpression: - selectExpression.ApplyProjection(); - shaperBody = new CosmosProjectionBindingRemovingExpressionVisitor( selectExpression, jObjectParameter, QueryCompilationContext.QueryTrackingBehavior == QueryTrackingBehavior.TrackAll) diff --git a/test/EFCore.Specification.Tests/CustomConvertersTestBase.cs b/test/EFCore.Specification.Tests/CustomConvertersTestBase.cs index fc74e6e6a51..ab699f0082c 100644 --- a/test/EFCore.Specification.Tests/CustomConvertersTestBase.cs +++ b/test/EFCore.Specification.Tests/CustomConvertersTestBase.cs @@ -523,7 +523,7 @@ public virtual void Where_conditional_bool_with_value_conversion_is_used() Assert.Equal("http://blog.com", result.Url); } - [ConditionalFact(Skip = "Issue #21142")] + [ConditionalFact] public virtual void Select_conditional_bool_with_value_conversion_is_used() { using var context = CreateContext(); diff --git a/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs b/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs index f947893268a..61b356c6177 100644 --- a/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs +++ b/test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs @@ -2315,6 +2315,8 @@ public virtual void Top_level_projection_track_entities_before_passing_to_client orderby p.Id select DtoFactory.CreateDto(p)).FirstOrDefault(); + RecordLog(); + Assert.NotNull(((dynamic)query).Single); } diff --git a/test/EFCore.Specification.Tests/OptimisticConcurrencyTestBase.cs b/test/EFCore.Specification.Tests/OptimisticConcurrencyTestBase.cs index b41cf1feec7..267be8ff135 100644 --- a/test/EFCore.Specification.Tests/OptimisticConcurrencyTestBase.cs +++ b/test/EFCore.Specification.Tests/OptimisticConcurrencyTestBase.cs @@ -276,10 +276,8 @@ public virtual Task null); } - [ConditionalFact(Skip = "Many-to-many relationships are not supported without CLR class for join table.")] - // TODO: See issue#1368 - public virtual Task - Attempting_to_delete_same_relationship_twice_for_many_to_many_results_in_independent_association_exception() + [ConditionalFact(Skip = "Issue#23411")] + public virtual Task Attempting_to_delete_same_relationship_twice_for_many_to_many_results_in_independent_association_exception() { return ConcurrencyTestAsync( c => @@ -292,10 +290,8 @@ public virtual Task null); } - [ConditionalFact(Skip = "Many-to-many relationships are not supported without CLR class for join table.")] - // TODO: See issue#1368 - public virtual Task - Attempting_to_add_same_relationship_twice_for_many_to_many_results_in_independent_association_exception() + [ConditionalFact(Skip = "Issue#23411")] + public virtual Task Attempting_to_add_same_relationship_twice_for_many_to_many_results_in_independent_association_exception() { return ConcurrencyTestAsync( c => diff --git a/test/EFCore.Specification.Tests/StoreGeneratedTestBase.cs b/test/EFCore.Specification.Tests/StoreGeneratedTestBase.cs index a0baaea9cab..d28e28d395d 100644 --- a/test/EFCore.Specification.Tests/StoreGeneratedTestBase.cs +++ b/test/EFCore.Specification.Tests/StoreGeneratedTestBase.cs @@ -44,7 +44,7 @@ private void ValueGenerationNegative() Assert.Throws(() => context.Add(new TEntity())).Message); } - [ConditionalFact(Skip = "Issue#15589")] + [ConditionalFact] public virtual void Value_generation_works_for_common_GUID_conversions() { ValueGenerationPositive(); diff --git a/test/EFCore.SqlServer.FunctionalTests/LazyLoadProxySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/LazyLoadProxySqlServerTest.cs index 826c23ad5a8..d5cd36ef91a 100644 --- a/test/EFCore.SqlServer.FunctionalTests/LazyLoadProxySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/LazyLoadProxySqlServerTest.cs @@ -433,17 +433,21 @@ FROM [Child] AS [c] } } - [ConditionalFact(Skip = "Issue#1015")] + [ConditionalFact] public override void Top_level_projection_track_entities_before_passing_to_client_method() { base.Top_level_projection_track_entities_before_passing_to_client_method(); Assert.Equal( - @"@__p_0='707' (Nullable = true) + @"SELECT TOP(1) [p].[Id], [p].[AlternateId], [p].[Discriminator] +FROM [Parent] AS [p] +ORDER BY [p].[Id] + +@__p_0='707' (Nullable = true) - SELECT [c].[Id], [c].[ParentId] - FROM [Child] AS [c] - WHERE [c].[ParentId] = @__p_0", +SELECT [s].[Id], [s].[ParentId] +FROM [Single] AS [s] +WHERE [s].[ParentId] = @__p_0", Sql, ignoreLineEndingDifferences: true); } diff --git a/test/EFCore.Tests/ChangeTracking/Internal/QueryFixupTest.cs b/test/EFCore.Tests/ChangeTracking/Internal/QueryFixupTest.cs index 1c5097e926c..950722205ce 100644 --- a/test/EFCore.Tests/ChangeTracking/Internal/QueryFixupTest.cs +++ b/test/EFCore.Tests/ChangeTracking/Internal/QueryFixupTest.cs @@ -888,18 +888,20 @@ public void Query_owned() }); } - [ConditionalFact(Skip = "Issue #16752")] + [ConditionalFact] public void Query_subowned() { Seed(); using var context = new QueryFixupContext(); var subDependent1 = context.Set() + .Include(a => a.OrderDetails.BillingAddress.OrderDetails.Order) .Select(o => o.OrderDetails.BillingAddress) - .Include(a => a.OrderDetails.Order).Single(); + .Single(); var subDependent2 = context.Set() + .Include(a => a.OrderDetails.ShippingAddress.OrderDetails.Order) .Select(o => o.OrderDetails.ShippingAddress) - .Include(a => a.OrderDetails.Order).Single(); + .Single(); AssertFixup( context,