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

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

Open
maumar opened this issue Oct 31, 2024 · 1 comment
Assignees
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Oct 31, 2024

query:

    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]
    public virtual Task Join_with_key_selectors_being_nested_anonymous_objects(bool async)
        => AssertQuery(
            async,
            ss => ss.Set<Customer>().Order().Take(10).Join(
                ss.Set<Order>(),
                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:

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'.

@maumar maumar self-assigned this Oct 31, 2024
@cincuranet cincuranet assigned roji and unassigned maumar Nov 7, 2024
@cincuranet cincuranet added this to the Backlog milestone Nov 7, 2024
@maumar
Copy link
Contributor Author

maumar commented Nov 7, 2024

somewhat related to #35038

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants