Any and inheritance

Posts   
 
    
Deividas
User
Posts: 44
Joined: 01-Oct-2010
# Posted on: 01-Nov-2010 18:35:30   
from s in metaData.ServiceProvider
where s.ServiceProviderRegions.Any()
select s;

Here ServiceProvider inherits from LegalPerson (when ServiceProvider doesn't inherit LegalPerson the query works fine). The query generates an error with message:

"The multi-part identifier "LPLA_2.ServiceProviderId" could not be bound. The multi-part identifier "LPLA_2.ServiceProviderId" could not be bound.".

The generated SQL is:

SELECT [LPLA_2].[ServiceProviderId]
FROM ( [DB].[dbo].[LegalPerson] [LPA_L3]
       LEFT JOIN [DB].[dbo].[ServiceProvider] [LPA_L4]  ON  [LPA_L3].[LegalPersonId]=[LPA_L4].[ServiceProviderId])
WHERE ( [LPA_L4].[ServiceProviderId] = [LPLA_2].[ServiceProviderId])

SELECT DISTINCT [LPA_L1].[CompanyCode] AS [F1_0], [LPA_L1].[LegalPersonId] AS [F1_1], [LPA_L1].[Name] AS [F1_2], [LPA_L2].[ServiceProviderId] AS [F2_3], [LPA_L2].[StateId] AS [F2_4]
FROM ( [DB].[dbo].[LegalPerson] [LPA_L1]
       INNER JOIN [DB].[dbo].[ServiceProvider] [LPA_L2]  ON  [LPA_L1].[LegalPersonId]=[LPA_L2].[ServiceProviderId])
WHERE ( ( (  EXISTS (SELECT [LPLA_2].[ServiceProviderId]
                     FROM ( [DB].[dbo].[LegalPerson] [LPA_L3]
                            LEFT JOIN [DB].[dbo].[ServiceProvider] [LPA_L4]  ON  [LPA_L3].[LegalPersonId]=[LPA_L4].[ServiceProviderId])
                     WHERE ( [LPA_L4].[ServiceProviderId] = [LPLA_2].[ServiceProviderId])))) AND ( [LPA_L2].[ServiceProviderId] IS NOT NULL))

I've attached a solution with DB schema and an llblgenproj file in case you need it.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Nov-2010 06:21:13   

Reproduced with the last dll posted some days ago in a thread of you. I don't know whether this is or isn't a know bug. This workaround should work:

var query = from s in metaData.ServiceProvider
            where s.ServiceProviderRegions.Count() > 0
            select s;
David Elizondo | LLBLGen Support Team
Deividas
User
Posts: 44
Joined: 01-Oct-2010
# Posted on: 02-Nov-2010 09:09:24   

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39906
Joined: 17-Aug-2003
# Posted on: 02-Nov-2010 14:14:25   

Sorry for the problems you ran into with Linq and inheritance flushed .

We'll look into why this fails. The Count() > 0 is a workaround, Any() should work.

Frans Bouma | Lead developer LLBLGen Pro
Deividas
User
Posts: 44
Joined: 01-Oct-2010
# Posted on: 02-Nov-2010 14:28:57   

Otis wrote:

Sorry for the problems you ran into with Linq and inheritance flushed .

Yeah, it is strange for me that I'm the first to report these problems. Linq is supported for quite a long time in LLBLGen. Anyway, it's not over yet, I know one more problem with inheritance, but I'm using a workaround for it. wink Will post it later.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39906
Joined: 17-Aug-2003
# Posted on: 02-Nov-2010 15:06:44   

Deividas wrote:

Otis wrote:

Sorry for the problems you ran into with Linq and inheritance flushed .

Yeah, it is strange for me that I'm the first to report these problems. Linq is supported for quite a long time in LLBLGen.

The problem you reported last week was indeed new, very odd that no-one ran into that before.

Any() is simple but complicated, the correlated subquery filter goes wrong in this particular scenario, and it's to be seen why.

Anyway, it's not over yet, I know one more problem with inheritance, but I'm using a workaround for it. wink Will post it later.

Glad it at least has a workaround wink .

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39906
Joined: 17-Aug-2003
# Posted on: 03-Nov-2010 14:20:11   

It's a problem which only occurs if the entity owning the collection is in a TPE hierarchy. I can reproduce it with (adventureworks)

var q = from s in metaData.Store
        where s.StoreContactCollection.Any()
        select s;

store is a subtype of customer. Looking into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39906
Joined: 17-Aug-2003
# Posted on: 03-Nov-2010 15:29:14   

The error seems to be that the relationship represented by the navigator isn't added to the relationcollection of the exists query, obviously causing alias errors. Looking into it.

(edit). It's the other way around: a join is added which shouldn't be there. Hmm...

(edit) the query (using our own query api elements) is perfectly fine. So it somehow goes wrong after that in the runtime...

(edit) the cause is that the fieldcompareset predicate which represents the Exist contains a correlated predicate to tie it to the query around it and the runtime tries to make sure this entity is reachable as it's in an inheritance hierarchy. This is wrong of course, however it's complex to determine in which particular case this shouldn't happen, as it seems this is not really a case which is distinguishable from the rest. disappointed

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39906
Joined: 17-Aug-2003
# Posted on: 03-Nov-2010 18:45:47   

Well, that took forever.. disappointed . But! it's fixed simple_smile

See attached ormsupportclasses. It was a very nasty bug.

Frans Bouma | Lead developer LLBLGen Pro