-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
ExecuteUpdate Produce Wrong Query when used with window function and join #31984
Comments
Note for triage: still repros with RC2 on both SQL Server and PostgreSQL. SQL Server SQL: fail: 10/12/2023 12:04:23.962 RelationalEventId.CommandError[20102] (Microsoft.EntityFrameworkCore.Database.Command)
Failed executing DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
UPDATE [p]
SET [p].[NetAmount] = CAST([p].[Quantity] AS decimal(18,2)) * [t1].[Rate],
[p].[LastCpWithoutVat] = CASE
WHEN [t1].[Rate] > 0.0 THEN ROUND(CASE
WHEN [p2].[VatPercent] > CAST(0 AS bigint) THEN [t1].[Rate] - CAST([p2].[VatPercent] / CAST(100 AS bigint) AS decimal(18,2)) * [t1].[Rate]
ELSE [t1].[Rate]
END, 3)
ELSE 0.0
END,
[p].[LastCp] = [t1].[Rate]
FROM [PurchaseOrders] AS [p]
INNER JOIN (
SELECT [p0].[ProductId], [p0].[UnitId], [t0].[ProductId] AS [ProductId0]
FROM [ProductUnitLinks] AS [p0]
INNER JOIN (
SELECT [t].[ProductId], [t].[UnitId]
FROM (
SELECT [p1].[ProductId], [p1].[UnitId], ROW_NUMBER() OVER(PARTITION BY [p1].[ProductId], [p1].[UnitId] ORDER BY [p1].[Date] DESC) AS [row]
FROM [ProductCps] AS [p1]
) AS [t]
WHERE [t].[row] <= 1
) AS [t0] ON [p0].[ProductId] = [t0].[ProductId] AND [p0].[UnitId] = [t0].[UnitId]
) AS [t1] ON [p].[ProductId] = [t1].[ProductId] AND [p].[UnitId] = [t1].[UnitId]
INNER JOIN [Products] AS [p2] ON [t1].[ProductId0] = [p2].[Id] |
Thanks for checking @ajcvickers. I don't have time for a deep investigation at the moment, but some chances of this being a dup of #31407. Let's keep this open and I'll prioritize looking at this along with #31407 once things calm down. |
Confirmed that this fails on 8.0.0 with SQL Server, but works with the latest daily build (9.0.0-alpha.1.24054.14). |
Duplicate of #31407 |
Hello,
I am facing an issue while performing ExecuteUpdate When using with window function and join query.
Following are the sample entity
Code To fetch LastCp Info using Window Function
Works fine while fetching the data producing correct SQL Query
Fails during ExecuteUpdate producing wrong SQL query
Stack traces
Produced query is missing column Rate, RateWithoutVat in select, resulting in error i.e. column Rate does not exist.
Also this issue only arises when including Product while fetching LastCp
It works fine when Include is removed.
Link to Project to reproduce error
Repo With Error
Include provider and version information
EF Core version: 7.0.11
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: .NET 7.0
Operating system: Window 10
IDE: JetBrains Rider
The text was updated successfully, but these errors were encountered: