GroupJoin with incorrect data

Data 339 is incorrectly linked with data 339 and 337
Comments
-
How is it possible that Id 339 is linked with IdGruppoTrazione 337 and 339?
-
Here's another example. I'm not sure if this is a LINQPad-specific bug, or a bug in .NET's LINQ-to-SQL. I'm using LINQPad v9 targeting a SQL Server database through LINQPad's built-in LINQ to SQL (optimized for SQL Server) driver.

-
This is indeed a bug in LINQ-to-SQL.
I've included a fix in 9.10.2. It now translates
HeapOuters.GroupJoin ( HeapInners, o => o.Id, i => i.IdOuter, (o, ins) => new { o.Id, Items = ins.ToList () } )to
SELECT [t1].[Id], [t2].[IdOuter], [t2].[Tipo], [t2].[Amount], ( SELECT COUNT(*) FROM ( SELECT NULL AS [EMPTY] FROM [HeapInner] AS [t3] WHERE [t1].[Id] = [t3].[IdOuter] ) AS [t4] ) AS [value] FROM ( SELECT ROW_NUMBER() OVER (ORDER BY [t0].[Id], [t0].[Name]) AS [ROW_NUMBER], [t0].[Id] FROM [HeapOuter] AS [t0] ) AS [t1] LEFT OUTER JOIN [HeapInner] AS [t2] ON [t1].[Id] = [t2].[IdOuter] ORDER BY [t1].[ROW_NUMBER]Let me know how you get on.

