From 1948de0e7a6f645d4a3266cf19d9b3a027718138 Mon Sep 17 00:00:00 2001 From: AndriySvyryd Date: Thu, 22 Aug 2019 13:16:11 -0700 Subject: [PATCH] Test for #9742 Resolves #9742 --- .../Query/QuerySqlGenerator.cs | 1 - .../Internal/SqlServerQuerySqlGenerator.cs | 1 - .../TestUtilities/FakeDiagnosticsLogger.cs | 1 - .../Query/IncludeTestBase.cs | 36 ++++++++++++++++++- .../Query/IncludeSqlServerTest.cs | 29 +++++++++++++++ 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/EFCore.Relational/Query/QuerySqlGenerator.cs b/src/EFCore.Relational/Query/QuerySqlGenerator.cs index 7650650e156..1bc9c415eee 100644 --- a/src/EFCore.Relational/Query/QuerySqlGenerator.cs +++ b/src/EFCore.Relational/Query/QuerySqlGenerator.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs index 8c36f64d379..e74e654bf7a 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs @@ -4,7 +4,6 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; -using Microsoft.EntityFrameworkCore.Storage; namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal { diff --git a/test/EFCore.Relational.Tests/TestUtilities/FakeDiagnosticsLogger.cs b/test/EFCore.Relational.Tests/TestUtilities/FakeDiagnosticsLogger.cs index d2f0f18e182..2bad1258bb1 100644 --- a/test/EFCore.Relational.Tests/TestUtilities/FakeDiagnosticsLogger.cs +++ b/test/EFCore.Relational.Tests/TestUtilities/FakeDiagnosticsLogger.cs @@ -4,7 +4,6 @@ using System; using System.Diagnostics; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.Diagnostics.Internal; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.Extensions.Logging; diff --git a/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs b/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs index a9d1f8f5e25..7baa77c21b7 100644 --- a/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/IncludeTestBase.cs @@ -11,7 +11,6 @@ using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.TestModels.Northwind; using Microsoft.EntityFrameworkCore.TestUtilities; -using Microsoft.EntityFrameworkCore.TestUtilities.Xunit; using Xunit; // ReSharper disable InconsistentNaming @@ -3192,6 +3191,41 @@ var customers } } + [ConditionalTheory] + [InlineData(false)] + [InlineData(true)] + public virtual void Include_collection_with_multiple_conditional_order_by(bool useString) + { + using (var context = CreateContext()) + { + var orders + = useString + ? context.Orders + .Include("OrderDetails") + .OrderBy(o => o.OrderID > 0) + .ThenBy(o => o.Customer != null ? o.Customer.City : String.Empty) + .Take(5) + .ToList() + : context.Orders + .Include(c => c.OrderDetails) + .OrderBy(o => o.OrderID > 0) + .ThenBy(o => o.Customer != null ? o.Customer.City : String.Empty) + .Take(5) + .ToList(); + + foreach (var order in orders) + { + CheckIsLoaded( + context, + order, + orderDetailsLoaded: true, + productLoaded: false, + customerLoaded: false, + ordersLoaded: false); + } + } + } + [ConditionalTheory] [InlineData(false)] [InlineData(true)] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/IncludeSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/IncludeSqlServerTest.cs index d8ab3f81228..2615dcfd5b3 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/IncludeSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/IncludeSqlServerTest.cs @@ -1010,6 +1010,35 @@ OFFSET @__p_0 ROWS ORDER BY [t].[ContactName], [t].[CustomerID], [o].[OrderID]"); } } + public override void Include_collection_with_multiple_conditional_order_by(bool useString) + { + base.Include_collection_with_multiple_conditional_order_by(useString); + + AssertSql( + @"@__p_0='5' + +SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate], [o0].[OrderID], [o0].[ProductID], [o0].[Discount], [o0].[Quantity], [o0].[UnitPrice] +FROM ( + SELECT TOP(@__p_0) [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], CASE + WHEN [o].[OrderID] > 0 THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END AS [c], CASE + WHEN [c].[CustomerID] IS NOT NULL THEN [c].[City] + ELSE N'' + END AS [c0] + FROM [Orders] AS [o] + LEFT JOIN [Customers] AS [c] ON [o].[CustomerID] = [c].[CustomerID] + ORDER BY CASE + WHEN [o].[OrderID] > 0 THEN CAST(1 AS bit) + ELSE CAST(0 AS bit) + END, CASE + WHEN [c].[CustomerID] IS NOT NULL THEN [c].[City] + ELSE N'' + END +) AS [t] +LEFT JOIN [Order Details] AS [o0] ON [t].[OrderID] = [o0].[OrderID] +ORDER BY [t].[c], [t].[c0], [t].[OrderID], [o0].[OrderID], [o0].[ProductID]"); + } public override void Then_include_collection_order_by_collection_column(bool useString) {