More Outer Join Alias Issues...

Posts   
 
    
rossmcw
User
Posts: 28
Joined: 27-Mar-2008
# Posted on: 15-May-2008 07:16:43   

I have found a problem when doing an outer join after a nested query. The following is a stripped down way to reproduce it (Northwind):

from ep in db.Employees.Where(f => f.Country == "UK")
                    join et in db.EmployeeTerritories on ep.EmployeeID equals et.EmployeeID into etg
                    from et in etg.DefaultIfEmpty()
                    select ep

This throws

An exception was caught during the execution of a retrieval query: The multi-part identifier "LPLA_2.EmployeeID" could not be bound..

With the following SQL

exec sp_executesql N'
SELECT  [LPA_L1].[EmployeeID], [LPA_L1].[LastName], [LPA_L1].[FirstName], [LPA_L1].[Title], 
        [LPA_L1].[TitleOfCourtesy], [LPA_L1].[BirthDate], [LPA_L1].[HireDate], [LPA_L1].[Address], [LPA_L1].[City], [LPA_L1].[Region], 
        [LPA_L1].[PostalCode], [LPA_L1].[Country], [LPA_L1].[HomePhone], [LPA_L1].[Extension], [LPA_L1].[Photo], [LPA_L1].[Notes], 
        [LPA_L1].[ReportsTo], [LPA_L1].[PhotoPath] 
FROM 
( 
    (
        SELECT  [LPLA_1].[EmployeeID], [LPLA_1].[LastName], [LPLA_1].[FirstName], 
                [LPLA_1].[Title], [LPLA_1].[TitleOfCourtesy], [LPLA_1].[BirthDate], [LPLA_1].[HireDate], [LPLA_1].[Address], [LPLA_1].[City], 
                [LPLA_1].[Region], [LPLA_1].[PostalCode], [LPLA_1].[Country], [LPLA_1].[HomePhone], [LPLA_1].[Extension], [LPLA_1].[Photo], 
                [LPLA_1].[Notes], [LPLA_1].[ReportsTo], [LPLA_1].[PhotoPath] 
        FROM    [Northwind].[dbo].[Employees] [LPLA_1]  
        WHERE 
        (
            (
                [LPLA_1].[Country] = @Country1
            )
        )
    ) [LPA_L1]  
    LEFT JOIN   [Northwind].[dbo].[EmployeeTerritories] [LPA_L2]  
        ON      [LPLA_2].[EmployeeID] = [LPA_L2].[EmployeeID]
)
',N'@Country1 nvarchar(15)',@Country1=N'UK'

Interestingly, it works if you use an inner join, likewise if you dont do the nested .Where() it runs fine.

Dont you just love Aliases! simple_smile

Thanks again!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39873
Joined: 17-Aug-2003
# Posted on: 15-May-2008 08:56:20   

Alias is my middle name wink How many times an issue is about a wrong alias... I stopped counting. And I payed a lot of attention to the alias system to get it right. simple_smile Will check it out.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39873
Joined: 17-Aug-2003
# Posted on: 15-May-2008 14:51:11   

Fixed it simple_smile It was a very obscure bug, where aliases of a groupjoin had to be rewritten, and as a clone was used, it didn't clone a part of the tree, so it was changing the wrong object wink

(edit) for a temporary build, see this post: http://www.llblgen.com/tinyforum/GotoMessage.aspx?MessageID=74230&ThreadID=13312 (does require latest temporary runtime lib build, available in this post: http://www.llblgen.com/tinyforum/GotoMessage.aspx?MessageID=74164&ThreadID=13312

Frans Bouma | Lead developer LLBLGen Pro