yang-er / efcore-ext

EFCore Extensions for batch-CRUD / cache / minor fix
MIT License
32 stars 6 forks source link

SQL generation error with salar subquery #12

Closed yang-er closed 2 years ago

yang-er commented 2 years ago

https://github.com/namofun/ccs/blob/4e8047522e71d9401d0c73ce6768d0d4d084f2e9/src/EntityFrameworkCore/Context/Immediate.Team.cs#L24-L33

This query is translated to

UPDATE [c]
SET [c].[TeamCount] = (
    SELECT COUNT(*)
    FROM [ContestTeams] AS [c]
    INNER JOIN [TenantCategory] AS [t] ON [c].[CategoryId] = [t].[Id]
    WHERE (([c].[ContestId] = [c].[Id]) AND ([c].[Status] = 1)) AND ([t].[IsPublic] = CAST(1 AS bit)))
FROM [Contests] AS [c]
WHERE [c].[Id] = @__cid_0

but expected to be

UPDATE [c1]
SET [c1].[TeamCount] = (
    SELECT COUNT(*)
    FROM [ContestTeams] AS [c]
    INNER JOIN [TenantCategory] AS [t] ON [c].[CategoryId] = [t].[Id]
    WHERE (([c].[ContestId] = [c1].[Id]) AND ([c].[Status] = 1)) AND ([t].[IsPublic] = CAST(1 AS bit)))
FROM [Contests] AS [c1]
WHERE [c1].[Id] = @__cid_0