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

Where condition missing on Left join grouped sub query #13216

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
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

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

@smitpatel smitpatel added the verify-fixed This issue is likely fixed in new query pipeline. label Mar 16, 2020
@bricelam bricelam modified the milestones: Backlog, MQ Sep 11, 2020
@maumar maumar added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed verify-fixed This issue is likely fixed in new query pipeline. labels Oct 1, 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants