3.0 regression: Produces invalid SQL for complex query
See original GitHub issueAfter upgrading to 3.0.0-rc2 daily builds from 2.2.6, a query previously working is now generating invalid SQL. It’s hard for me to make a small reproducible example since it renders into a complex query with lots of columns and joins (292 lines long…), but this is an outline of the resulting query:
SELECT [t14].[lots of columns..], [t21].[lots of columns..], [t28].[lots of columns..]
FROM (
SELECT TOP(1) [lots of columns..]
FROM [a table]
INNER JOIN [other tables..]
LEFT JOIN [**The Missing Table**] AS [t] ON [...]
--- here is the table joined in as [t]
LEFT JOIN [other tables..]
WHERE [several filters]
ORDER BY [a column]
) AS [t14]
OUTER APPLY (
SELECT [t].[a column], [...]
--- this is the error, it tries to reach [t] in this outer apply
) AS [t21]
OUTER APPLY (
[other things]
) AS [t28]
LEFT JOIN [...]
[...]
ORDER BY [t14].[lots of columns..], [t21].[lots of columns..], [t28].[lots of columns..]
As you can see it tries to reach [t] from within outer apply but it’s declared in another scope. How do I proceed to investigate this so that I can give you better details of this problem? I do not even know where to start debugging this to make EF Core produce a valid SQL. Perhaps this is something you know about and are already working on right now?
Further technical details
EF Core version: 3.0.0-rc2 daily builds Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET Core 3.0 Operating system: Win 10 IDE: Visual Studio 2019 preview
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:31 (30 by maintainers)
@jcemoller - Received. Give me few days to investigate. It is a massive query. 😆
Thanks @smitpatel , I will try this work-around next week. Just wanted to let you know that I have now worked out all (*) the migration issues - and this week we’re finally live with 3.0 code in production! Preliminary results look promising, we’re seeing on average http request times going down from 70 ms to 54 ms with net/ef core 3.0 compared to 2.2.6! Great work!
* I had to skip a single integration test due to some regression in memory provider, will post issue later when I got time to package a reproducible example.