The multi-part identifier could not be bound.

Posts   
1  /  2
 
    
mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 16-Aug-2010 10:24:37   

Testing...

**(edit) **Thank you Frans. Nice workaround in re-using rateQSnippet with rateQ1 and rateQ2.

BTW.. writing complex and massive queries like this using LLBLLinq provider is making LLBLLinq provider more solid. Maybe its worth rewarding a free LLBL license simple_smile simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 16-Aug-2010 11:16:23   

heh simple_smile

Well, to solve this we actually have to start over at 40/50% of the linq provider and re-do the remaining 50/60% again using a different approach. That will take months to complete, but in the end might be the better option to go for, as it might also solve other edge-cases we ran into in the past.

I'm glad this workaround gets you work around the issue without compromising the maintainability of the code simple_smile

Frans Bouma | Lead developer LLBLGen Pro
mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 17-Aug-2010 11:00:18   

now I am facing the same bug with the same query after extending its expression to include the remaining joins. I have tried to use the same workaround you suggested but with no use !!

Attached is the project to help in reproducing the bug

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 17-Aug-2010 14:52:15   

Query works on v3, fails on 2.6. Also when I uncomment the lines, the query works on v3 and not on v2.6.

Very likely due to the multiple times an alias is assigned to a member of an anonymous type. This is a limitation of the v2.6 version, and the fix in v3 can't be ported back to v2.6 due to the changes required for that.

I'll see if I can make things workable by altering some things in the query.

However, it's likely also a sign that sooner or later, you'll run into a problem with these queries and v2.6 linq anyway: the vast majority of the queries work, but edge-case massive queries sometimes fail.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 17-Aug-2010 15:14:24   

v2.6 query, aliases un-mangled (as there's no inheritance, this is safe)

SELECT [LPLA_28].[PortfolioNo], [LPLA_28].[SecurityEName], [LPLA_28].[AmountCcyBalance] FROM ((SELECT COALESCE([LPLA_1].[PFNo], 0 /* @LO01 /) AS [PortfolioNo], COALESCE([LPLA_1].[SecCode], 0 / @LO02 /) AS [SecurityEName], COALESCE([LPLA_1].[AmountBalance], 0 / @LO03 /) AS [AmountCcyBalance] FROM (((SELECT [LPLA_5].[LPAV_1] AS [TrxNo], [LPLA_5].[SecCode] FROM (SELECT [LPLA_2].[PFNo], [LPLA_2].[SecCode], MAX([LPLA_2].[TrxNo]) AS [LPAV], MAX([LPLA_2].[TrxNo]) AS [LPAV_1] FROM ([LLBLTest].[dbo].[Transactions] [LPLA_2] INNER JOIN [LLBLTest].[dbo].[PortfolioData] [LPLA_3] ON [LPLA_2].[PFNo] = [LPLA_3].[PortfolioID]) WHERE (((([LPLA_2].[TrxDate] <= '2011-01-01T00:00:00.00' / @TrxDate4 /) AND ([LPLA_2].[trxTypeNormal] = 1 / @TrxTypeNormal5 /)))) GROUP BY [LPLA_2].[PFNo], [LPLA_2].[SecCode]) [LPLA_5] WHERE ((([LPLA_5].[LPAV] > 0 / @LPAV_6 /)))) [LPLA_9] INNER JOIN [LLBLTest].[dbo].[Transactions] [LPLA_1] ON [LPLA_1].[TrxNo] = [LPLA_9].[TrxNo]) INNER JOIN [LLBLTest].[dbo].[SecurityData] [LPLA_12] ON [LPLA_1].[SecCode] = [LPLA_12].[Code])) [LPLA_30] LEFT JOIN (SELECT COALESCE([LPLA_15].[PFNo], 0 / @LO07 /) AS [PortfolioNo], COALESCE([LPLA_15].[SecCode], 0 / @LO08 /) AS [SecurityEName], COALESCE([LPLA_15].[AmountBalance], 0 / @LO09 /) AS [AmountCcyBalance] FROM (((SELECT [LPLA_19].[LPAV_1] AS [TrxNo], [LPLA_19].[SecCode] FROM (SELECT [LPLA_30].[PFNo], [LPLA_30].[SecCode], MAX([LPLA_14].[TrxNo]) AS [LPAV], MAX([LPLA_14].[TrxNo]) AS [LPAV_1] FROM ([LLBLTest].[dbo].[Transactions] [LPLA_16] INNER JOIN [LLBLTest].[dbo].[PortfolioData] [LPLA_17] ON [LPLA_16].[PFNo] = [LPLA_17].[PortfolioID]) WHERE (((([LPLA_30].[TrxDate] <= '2011-01-01T00:00:00.00' / @TrxDate10 /) AND ([LPLA_30].[trxTypeNormal] = 1 / @TrxTypeNormal11 /)))) GROUP BY [LPLA_30].[PFNo], [LPLA_30].[SecCode]) [LPLA_19] WHERE ((([LPLA_19].[LPAV] > 0 / @LPAV_12 */)))) [LPLA_23] INNER JOIN [LLBLTest].[dbo].[Transactions] [LPLA_15] ON [LPLA_15].[TrxNo] = [LPLA_23].[TrxNo]) INNER JOIN [LLBLTest].[dbo].[SecurityData] [LPLA_26] ON [LPLA_15].[SecCode] = [LPLA_26].[Code])) [LPLA_28] ON ([LPLA_30].[PortfolioNo] = [LPLA_28].[PortfolioNo] AND [LPLA_30].[SecurityEName] = [LPLA_28].[SecurityEName]))

v3.0 query, not beautified by LLBLGenProf, as it bugs currently with queries with too many subqueries, so hand beautified:

SELECT [LPLA_34].[PortfolioNo], [LPLA_34].[SecurityEName], [LPLA_34].[AmountCcyBalance] FROM ( ( SELECT COALESCE([LPLA_1].[PFNo], @p2) AS [PortfolioNo], COALESCE([LPLA_1].[SecCode], @p4) AS [SecurityEName], COALESCE([LPLA_1].[AmountBalance], @p6) AS [AmountCcyBalance] FROM ((( ( SELECT [LPLA_5].[LPAV_1] AS [TrxNo], [LPLA_5].[SecCode] FROM ( SELECT [LPLA_2].[PFNo], [LPLA_2].[SecCode], MAX([LPLA_2].[TrxNo]) AS [LPAV], MAX([LPLA_2].[TrxNo]) AS [LPAV_1] FROM ( [LLBLTest].[dbo].[Transactions] [LPLA_2]
INNER JOIN [LLBLTest].[dbo].[PortfolioData] [LPLA_3] ON [LPLA_2].[PFNo] = [LPLA_3].[PortfolioID]) WHERE ( ( ( ( [LPLA_2].[TrxDate] <= @p7) AND ( [LPLA_2].[trxTypeNormal] = @p8 )))) GROUP BY [LPLA_2].[PFNo], [LPLA_2].[SecCode] ) [LPLA_5] WHERE ( ( ( [LPLA_5].[LPAV
] > @p10))) ) [LPLA_9]
INNER JOIN [LLBLTest].[dbo].[Transactions] [LPLA_1] ON [LPLA_1].[TrxNo] = [LPLA_9].[TrxNo]) INNER JOIN [LLBLTest].[dbo].[PortfolioData] [LPLA_12] ON [LPLA_1].[PFNo] = [LPLA_12].[PortfolioID]) INNER JOIN [LLBLTest].[dbo].[SecurityData] [LPLA_15] ON [LPLA_1].[SecCode] = [LPLA_15].[Code]) ) [LPLA_36]
LEFT JOIN ( SELECT COALESCE([LPLA_18].[PFNo], @p12) AS [PortfolioNo], COALESCE([LPLA_18].[SecCode], @p14) AS [SecurityEName], COALESCE([LPLA_18].[AmountBalance], @p16) AS [AmountCcyBalance] FROM ((( ( SELECT [LPLA_22].[LPAV_1] AS [TrxNo], [LPLA_22].[SecCode] FROM ( SELECT [LPLA_19].[PFNo], [LPLA_19].[SecCode], MAX([LPLA_19].[TrxNo]) AS [LPAV], MAX([LPLA_19].[TrxNo]) AS [LPAV_1] FROM ( [LLBLTest].[dbo].[Transactions] [LPLA_19]
INNER JOIN [LLBLTest].[dbo].[PortfolioData] [LPLA_20] ON [LPLA_19].[PFNo] = [LPLA_20].[PortfolioID]) WHERE ( ( ( ( [LPLA_19].[TrxDate] <= @p17) AND ( [LPLA_19].[trxTypeNormal] = @p18 )))) GROUP BY [LPLA_19].[PFNo], [LPLA_19].[SecCode] ) [LPLA_22] WHERE ( ( ( [LPLA_22].[LPAV
] > @p20))) ) [LPLA_26]
INNER JOIN [LLBLTest].[dbo].[Transactions] [LPLA_18] ON [LPLA_18].[TrxNo] = [LPLA_26].[TrxNo]) INNER JOIN [LLBLTest].[dbo].[PortfolioData] [LPLA_29] ON [LPLA_18].[PFNo] = [LPLA_29].[PortfolioID]) INNER JOIN [LLBLTest].[dbo].[SecurityData] [LPLA_32] ON [LPLA_18].[SecCode] = [LPLA_32].[Code]) ) [LPLA_34] ON ( [LPLA_36].[PortfolioNo] = [LPLA_34].[PortfolioNo] AND [LPLA_36].[SecurityEName] = [LPLA_34].[SecurityEName]))

Error on v2.6: The multi-part identifier "LPLA_30.TrxDate" could not be bound. The multi-part identifier "LPLA_30.trxTypeNormal" could not be bound. The multi-part identifier "LPLA_30.PFNo" could not be bound. The multi-part identifier "LPLA_30.SecCode" could not be bound. The multi-part identifier "LPLA_30.PFNo" could not be bound. The multi-part identifier "LPLA_30.SecCode" could not be bound. The multi-part identifier "LPLA_14.TrxNo" could not be bound. The multi-part identifier "LPLA_14.TrxNo" could not be bound.

I still think this is due to re-aliasing of the same anonymous type, however I'll look into whether this is indeed the case, or that another issue we've fixed in v3 is the reason why it works in v3.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 17-Aug-2010 15:25:41   

It's indeed the issue I described earlier (previous page of this thread). You can see it in the query: WHERE (((([LPLA_30].[TrxDate] <= '2011-01-01T00:00:00.00' /* @TrxDate10 /) AND ([LPLA_30].[trxTypeNormal] = 1 / @TrxTypeNormal11 */))))

this is the second part, and it refers to LPLA_30. This is the left side of the LEFT JOIN, which contains exactly the same query fragment. As the member is aliased just once, it has the same alias for both sides, and as for the right side it isn't in-scope it gets the alias of it outer scope, LPLA_30. This is wrong, but not fixable in v2.6, we made a lot of changes to make this possible in v3.

So, to avoid you losing any more time over this, and not pushing you into v3 upgrades if you don't want to (as I said earlier, large queries still might break in v3, as we've seen before in this thread), I think it's better if you rewrite the query in our own query system. This might be a little more verbose (although with some helper methods (you can use the same trick to use a method to produce the query parts for both sides) this is made easier) but at least these queries always work.

Frans Bouma | Lead developer LLBLGen Pro
1  /  2