A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
Method Enter: CreatePagingSelectDQ
Method Enter: CreateSelectDQ
Method Enter: CreateSelectDQ
Generated Sql query:
Query: SELECT DISTINCT [AdventureWorks].[HumanResources].[EmployeeNested].[EmployeeId], [AdventureWorks].[HumanResources].[EmployeeNested].[lft] AS [Lft], [AdventureWorks].[HumanResources].[EmployeeNested].[rgt] AS [Rgt] FROM ( [AdventureWorks].[HumanResources].[EmployeeNested] [LPA_P1] INNER JOIN [AdventureWorks].[HumanResources].[EmployeeNested] [LPA_P2] ON ( [LPA_P2].[lft] > [LPA_P1].[lft] AND [LPA_P2].[lft] < [LPA_P1].[rgt] AND [LPA_P1].[EmployeeId] = @EmployeeId1))
Parameter: @EmployeeId1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 3.
Method Exit: CreateSelectDQ
Method Exit: CreatePagingSelectDQ: no paging.
A first chance exception of type 'SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException' occurred in SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll
'emp.GetSubOrinates(2)' threw an exception of type 'SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException'
base {SD.LLBLGen.Pro.ORMSupportClasses.ORMException}: {"An exception was caught during the execution of a retrieval query: The multi-part identifier \"AdventureWorks.HumanResources.EmployeeNested.EmployeeId\" could not be bound.\r\nThe multi-part identifier \"AdventureWorks.HumanResources.EmployeeNested.lft\" could not be bound.\r\nThe multi-part identifier \"AdventureWorks.HumanResources.EmployeeNested.rgt\" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."}
Parameters: {System.Data.SqlClient.SqlParameterCollection}
QueryExecuted: "\r\n\tQuery: SELECT DISTINCT [AdventureWorks].[HumanResources].[EmployeeNested].[EmployeeId], [AdventureWorks].[HumanResources].[EmployeeNested].[lft] AS [Lft], [AdventureWorks].[HumanResources].[EmployeeNested].[rgt] AS [Rgt] FROM ( [AdventureWorks].[HumanResources].[EmployeeNested] [LPA_P1] INNER JOIN [AdventureWorks].[HumanResources].[EmployeeNested] [LPA_P2] ON ( [LPA_P2].[lft] > [LPA_P1].[lft] AND [LPA_P2].[lft] < [LPA_P1].[rgt] AND [LPA_P1].[EmployeeId] = @EmployeeId1))\r\n\tParameter: @EmployeeId1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 3.\r\n"
When runnin the created query in MsSqlManagment studio:
SELECT DISTINCT [AdventureWorks].[HumanResources].[EmployeeNested].[EmployeeId], [AdventureWorks].[HumanResources].[EmployeeNested].[lft] AS [Lft], [AdventureWorks].[HumanResources].[EmployeeNested].[rgt] AS [Rgt] FROM ( [AdventureWorks].[HumanResources].[EmployeeNested] [LPA_P1] INNER JOIN [AdventureWorks].[HumanResources].[EmployeeNested] [LPA_P2] ON ( [LPA_P2].[lft] > [LPA_P1].[lft] AND [LPA_P2].[lft] < [LPA_P1].[rgt] AND [LPA_P1].[EmployeeId] = 3))
I get
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "AdventureWorks.HumanResources.EmployeeNested.EmployeeId" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "AdventureWorks.HumanResources.EmployeeNested.lft" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "AdventureWorks.HumanResources.EmployeeNested.rgt" could not be bound.
Replacing AdventureWorks.HumanResources.EmployeeNested with [LPA_P2]
SELECT DISTINCT [LPA_P2].[EmployeeId], [LPA_P2].[lft] AS [Lft],[LPA_P2].[rgt] AS [Rgt] FROM ( [AdventureWorks].[HumanResources].[EmployeeNested] [LPA_P1] INNER JOIN [AdventureWorks].[HumanResources].[EmployeeNested] [LPA_P2] ON ( [LPA_P2].[lft] > [LPA_P1].[lft] AND [LPA_P2].[lft] < [LPA_P1].[rgt] AND [LPA_P1].[EmployeeId] = 3))
Gets me the exact query I was trying to create.
The table in question is:
CREATE TABLE [HumanResources].[EmployeeNested](
[EmployeeId] [int] NOT NULL,
[lft] [int] NULL,
[rgt] [int] NULL,
CONSTRAINT [PK_EmployeeNested] PRIMARY KEY CLUSTERED
(
[EmployeeId] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]