Skip to content

Where condition missing on Left join grouped sub query #13216

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
tai-yi opened this issue Sep 5, 2018 · 1 comment · Fixed by #22897
Closed

Where condition missing on Left join grouped sub query #13216

tai-yi opened this issue Sep 5, 2018 · 1 comment · Fixed by #22897

Comments

@tai-yi
Copy link

tai-yi commented Sep 5, 2018

I want left join twice, first is a grouped sub query, second is a table.

The major translation works well.

But the condition has some problem, if LINQ condtion constains the grouped query part, the translation will not translate condition part.

Steps to reproduce

Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

Tables

Users
userid, username
SupperFCWacher
id, userid
FCWacher
id , userid, dealerid

Users

LINQ

var data = from u in _dbContext.Users
                       join s in _dbContext.SupperFCWachers
                       on u.Id equals s.UserId
                       into su
                       from m in su.DefaultIfEmpty()

                       join wg in (from w in _dbContext.FCWachers group w by w.UserId into g select new { UserId = g.Key, Count = g.Count() }
                       )
                       on u.Id equals wg.UserId
                       into wu
                       from n in wu.DefaultIfEmpty()
                       where m.Id != null || n.Count > 0
                       select new FCWacherSummaryModel()
                       {
                           UserId = u.Id,
                           UserName = u.UserName,
                           Description = m == null ? "" : "All Dealers"
                       };

Translated SQL

SELECT [t].[UserId], [t].[Count], [s].[Id], [u].[UserID] AS [UserId0], [u].[UserName], CASE
    WHEN [s].[Id] IS NULL
    THEN N'' ELSE N'All Dealers'
END AS [Description]
FROM [UserDefinition] AS [u]
LEFT JOIN [SupperFCWacher] AS [s] ON [u].[UserID] = [s].[UserId]
LEFT JOIN (
    SELECT [w].[UserId], COUNT(*) AS [Count]
    FROM [FCWacher] AS [w]
    GROUP BY [w].[UserId]
) AS [t] ON [u].[UserID] = [t].[UserId]
--where s.id is not null or t.Count>0   --!!this condition will not be translated.

Another Issue

If FCWacher inherit SupperFCWacher, the translated sql will be error.

Further technical details

EF Core version: (2.1.1)
Database Provider: (Microsoft.EntityFrameworkCore.SqlServer)
Operating system:
IDE: (e.g. Visual Studio 2017 15.4)

@icesasoftcorp
Copy link

please the solution to this problem

@bricelam bricelam modified the milestones: Backlog, MQ Sep 11, 2020
maumar added a commit that referenced this issue Oct 6, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
maumar added a commit that referenced this issue Oct 6, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
maumar added a commit that referenced this issue Oct 6, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
maumar added a commit that referenced this issue Oct 6, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
maumar added a commit that referenced this issue Oct 6, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
maumar added a commit that referenced this issue Oct 6, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
maumar added a commit that referenced this issue Oct 6, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
maumar added a commit that referenced this issue Oct 6, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
maumar added a commit that referenced this issue Oct 7, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
maumar added a commit that referenced this issue Oct 7, 2020
Resolves #10295
Resolves #12453
Resolves #13216
Resolves #13550
Resolves #13712
Resolves #13977
Resolves #15302
Resolves #17735
@maumar maumar closed this as completed in 2403579 Oct 7, 2020
@ajcvickers ajcvickers modified the milestones: MQ, 6.0.0 Nov 25, 2020
@ajcvickers ajcvickers removed this from the 6.0.0 milestone Jan 27, 2021
@ajcvickers ajcvickers added this to the 6.0.0-preview1 milestone Jan 27, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview1, 6.0.0 Nov 8, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants