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

[6.0.2] Query: Assign proper type to CollectionResultExpression #27134

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio
_queryableMethodTranslatingExpressionVisitor.TranslateSubquery(
materializeCollectionNavigationExpression.Subquery)!);
return new CollectionResultExpression(
// expression.Type will be CLR type of the navigation here so that is fine.
new ProjectionBindingExpression(_selectExpression, _clientProjections.Count - 1, expression.Type),
materializeCollectionNavigationExpression.Navigation,
materializeCollectionNavigationExpression.Navigation.ClrType.GetSequenceType());
Expand All @@ -176,6 +177,7 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio
if (subquery != null)
{
_clientProjections!.Add(subquery);
// expression.Type here will be List<T>
return new CollectionResultExpression(
new ProjectionBindingExpression(_selectExpression, _clientProjections.Count - 1, expression.Type),
navigation: null,
Expand All @@ -195,8 +197,17 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio
}

_clientProjections!.Add(subquery);
var type = expression.Type;
if (!(AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue27105", out var enabled) && enabled))
{
if (type.IsGenericType
&& type.GetGenericTypeDefinition() == typeof(IQueryable<>))
{
type = typeof(IEnumerable<>).MakeGenericType(type.GetSequenceType());
}
}
var projectionBindingExpression = new ProjectionBindingExpression(
_selectExpression, _clientProjections.Count - 1, expression.Type);
_selectExpression, _clientProjections.Count - 1, type);
return subquery.ResultCardinality == ResultCardinality.Enumerable
? new CollectionResultExpression(
projectionBindingExpression, navigation: null, subquery.ShaperExpression.Type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,12 @@ public override Task MemberInit_in_projection_without_arguments(bool async)
return base.MemberInit_in_projection_without_arguments(async);
}

[ConditionalTheory(Skip = "Cross collection join Issue#17246")]
public override Task List_of_list_of_anonymous_type(bool async)
{
return base.List_of_list_of_anonymous_type(async);
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2446,5 +2446,31 @@ public virtual Task MemberInit_in_projection_without_arguments(bool async)
AssertEqual(e.Orders.Count(), a.Orders.Count());
});
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task List_of_list_of_anonymous_type(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Customer>()
.Where(c => c.CustomerID.StartsWith("F"))
.Select(c => new
{
c.CustomerID,
ListWithSubList = c.Orders.OrderBy(e => e.OrderID).Select(o => o.OrderDetails.Select(e => new
{
e.OrderID,
e.ProductID
}))
}),
elementSorter: e => e.CustomerID,
elementAsserter: (e, a) =>
{
AssertEqual(e.CustomerID, a.CustomerID);
AssertCollection(e.ListWithSubList, a.ListWithSubList, ordered: true,
elementAsserter: (ee, aa) => AssertCollection(ee, aa, elementSorter: i => (i.OrderID, i.ProductID)));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,22 @@ WHERE [c].[CustomerID] LIKE N'F%'
ORDER BY [c].[CustomerID]");
}

public override async Task List_of_list_of_anonymous_type(bool async)
{
await base.List_of_list_of_anonymous_type(async);

AssertSql(
@"SELECT [c].[CustomerID], [t].[OrderID], [t].[OrderID0], [t].[ProductID]
FROM [Customers] AS [c]
LEFT JOIN (
SELECT [o].[OrderID], [o0].[OrderID] AS [OrderID0], [o0].[ProductID], [o].[CustomerID]
FROM [Orders] AS [o]
LEFT JOIN [Order Details] AS [o0] ON [o].[OrderID] = [o0].[OrderID]
) AS [t] ON [c].[CustomerID] = [t].[CustomerID]
WHERE [c].[CustomerID] LIKE N'F%'
ORDER BY [c].[CustomerID], [t].[OrderID], [t].[OrderID0]");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down