Skip to content

Commit

Permalink
Test for #9742
Browse files Browse the repository at this point in the history
Resolves #9742
  • Loading branch information
AndriySvyryd committed Aug 23, 2019
1 parent 10895a9 commit 7f65331
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/EFCore.Relational/Query/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
36 changes: 35 additions & 1 deletion test/EFCore.Specification.Tests/Query/IncludeTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,36 @@ OFFSET @__p_0 ROWS
}
}

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)
{
base.Then_include_collection_order_by_collection_column(useString);
Expand Down

0 comments on commit 7f65331

Please sign in to comment.