dotnet / dotnet/efcore

Query: invalid SQL generated when doing join with nested anonymous key selectors

Open
#35,028 1 comment 0 reactions 0 assignees View on GitHub
area-query
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

query:

```cs
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Join_with_key_selectors_being_nested_anonymous_objects(bool async)
=> AssertQuery(
async,
ss => ss.Set().Order().Take(10).Join(
ss.Set(),
x => new { x.CustomerID, Nested = new { x.City, Year = 1996 } },
x => new { x.CustomerID, Nested = new { City = "London", x.OrderDate.Value.Year } },
(c, o) => new { c, o }),
elementSorter: e => (e.c.CustomerID, e.o.OrderID ),
elementAsserter: (e, a) =>
{
AssertEqual(e.c, a.c);
AssertEqual(e.o, a.o);
});
```

sql:

```sql
SELECT [c0].[CustomerID], [c0].[Address], [c0].[City], [c0].[CompanyName], [c0].[ContactName], [c0].[ContactTitle], [c0].[Country], [c0].[Fax], [c0].[Phone], [c0].[PostalCode], [c0].[Region], [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM (
SELECT TOP(@__p_0) [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
ORDER BY [c].[CustomerID]
) AS [c0]
INNER JOIN [Orders] AS [o] ON [c0].[CustomerID] = [o].[CustomerID] AND -- <-- error here
ORDER BY [c0].[CustomerID]
```

error:
Microsoft.Data.SqlClient.SqlException : Incorrect syntax near the keyword 'ORDER'.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.