LLBL The multi-part identifier [FIELDNAME] could not be bound

Posts   
 
    
khanhtl
User
Posts: 4
Joined: 17-Oct-2019
# Posted on: 17-Oct-2019 05:46:28   

Hi Team,

I run code

LLBL version 5.5

using (DataAccessAdapter adapter = ...)
            {               
                FES.MortgageEzy.Shared.Database.Linq.LinqMetaData linq = new FES.MortgageEzy.Shared.Database.Linq.LinqMetaData(adapter);                
                return linq.Loans.IncludeFields(l => l.ApplicationID)
                    .Where(l => l.Status.Any(st => st.ConfigLoanStatus.MStatusID == 22) && l.Date_Settled == null)
                    .Select(l => l.ApplicationID.ToString()).ToList();
            }

It raised exception with message below

{"An exception was caught during the execution of a retrieval query: The multi-part identifier \"LPLA_1.ApplicationID\" could not be bound.\r\nThe multi-part identifier \"LPLA_1.Date_Settled\" could not be bound.\r\nThe multi-part identifier \"LPLA_1.ApplicationID\" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."}

I check the sql query from profiler

exec sp_executesql N'SELECT CONVERT(NVARCHAR(10), [LPLA_1].[ApplicationID]) AS [LPFA_1] FROM [SoEzyDB].[dbo].[Loans] [LPA_L1] WHERE ( ( ( ( (  EXISTS (SELECT [LPA_L3].[ValuationId] FROM ([SoEzyDB].[dbo].[ConfigLoanStatus] [LPA_L2] RIGHT JOIN [SoEzyDB].[dbo].[Status] [LPA_L3] ON [LPA_L2].[ConfigLoanStatusId]=[LPA_L3].[ConfigStatusID]) WHERE ( [LPLA_1].[ApplicationID] = [LPA_L3].[ApplicationID] AND ( [LPA_L2].[MStatusID] = @p1))) AND ( [LPLA_1].[Date_Settled] IS NULL))))))',N'@p1 int',@p1=22
go
  • The query is wrong
  • "SELECT CONVERT(NVARCHAR(10), [LPLA_1].[ApplicationID]",
  • [LPLA_1] is not alias of table Loans, it is [LPA_L1]
  • FROM [SoEzyDB].[dbo].[Loans] [LPA_L1]

Please me the way to fix this issue. Thank you,

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-Oct-2019 09:24:32   

We'll look into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-Oct-2019 10:00:19   

Problem seems to be the include fields at that position. Looking into it (when I remove the includefields call, the query works. ) Moving the IncludeFields after the where makes it work btw.

'IncludeFields' is a projection call for entities. As you have a custom projection on the query, it has no effect (it's not honored inside a SQL query for instance).

Could you elaborate why you have it this way? I.e. did you have another query which failed and this one looked like it?

Frans Bouma | Lead developer LLBLGen Pro
khanhtl
User
Posts: 4
Joined: 17-Oct-2019
# Posted on: 18-Oct-2019 07:35:38   

Thank you very much, I removed it and solved the issue.

khanhtl
User
Posts: 4
Joined: 17-Oct-2019
# Posted on: 25-Oct-2019 08:07:36   

Our source code have a lot of code like this. We just upgrade source code from LLBL 2.3 to LLBL 5.5 - with LLBL 2.3: it run good with code like above. - but with LLBL 5.5, we have to change source code to fix the error. There are a lot of

will LLBL fix this bug in near feature?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 25-Oct-2019 09:27:07   

We have a workitem for it, but in practice it doesn't make sense to have the include on a query with a projection as it's not used. If you have the include on a query which fetches entities, then it should work fine.

It's odd that it does work on 2.6 and not on the latest linq provider. You have many queries which fail?

Frans Bouma | Lead developer LLBLGen Pro
khanhtl
User
Posts: 4
Joined: 17-Oct-2019
# Posted on: 25-Oct-2019 09:30:52   

Yes, the project I joined too big. and I found 473 line of code statement like that.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 25-Oct-2019 10:22:55   

khanhtl wrote:

Yes, the project I joined too big. and I found 473 line of code statement like that.

Ok, but if they're entity fetching queries then it should be fine and they should work. For queries which fail and have a projection, they can be removed. For queries which fetch entities, and which fail, move the Include() to the outside of the query, e.g. before the select or right after it.

I would only worry about the queries which fail, I doubt they all fail.

Btw, we always fetch fk and pk fields, so specifying these in include/exclude method calls is a no-op

Frans Bouma | Lead developer LLBLGen Pro