efcore icon indicating copy to clipboard operation
efcore copied to clipboard

GroupBy with LEFT JOIN field not translated to SQL Server GROUP BY

Open alexfestbaum opened this issue 8 years ago • 3 comments

Upon testing the awesome new group by functionality of EF Core Preview 2 we found that grouping on a field originating from a LEFT JOINed entity is translated to ORDER BY and not the expected GROUP BY when issued against the SQL Server provider.

Steps to reproduce

var query = from transactions in context.TRANS
            join signer in context.Users
              on transactions.SIGNED_BY equals signer.Id into signerGroup
            from signer in signerGroup.DefaultIfEmpty()
            select signer;
var groupedValues = query.GroupBy(g => g.Email).Select(s => s.Key).ToList();

This evaluates to:

SELECT [signer].[Email]
FROM [TRANS] AS [transactions]
LEFT JOIN [Users] AS [signer] ON [transactions].[SIGNED_BY] = [signer].[Id]
ORDER BY [signer].[Email]

, where we actually would expect GROUP BY. Furthermore if we change this to an INNER JOIN it is translated to GROUP BY instead.

Further technical details

EF Core version: 2.1.0-preview2-final Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 10 Enterprise IDE: Visual Studio 15.6.6

alexfestbaum avatar Apr 20 '18 08:04 alexfestbaum

@smitpatel Can you investigate this?

ajcvickers avatar Apr 20 '18 18:04 ajcvickers

This is getting translated to Server GroupBy in 2.1.0-rc1-30613

smitpatel avatar Apr 20 '18 19:04 smitpatel

Fixed in #11700

smitpatel avatar Apr 20 '18 19:04 smitpatel