Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for #9742 #17402

Merged
merged 1 commit into from
Aug 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/EFCore.Relational/Query/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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
{
Original file line number Diff line number Diff line change
@@ -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;

36 changes: 35 additions & 1 deletion test/EFCore.Specification.Tests/Query/IncludeTestBase.cs
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert the sql

{
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)]
Original file line number Diff line number Diff line change
@@ -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);