linq count in where clause not working?

Posts   
 
    
pt
User
Posts: 23
Joined: 24-Dec-2009
# Posted on: 11-Feb-2010 22:47:44   

I am having trouble selecting items based off if there are records 0 records in a related entity collection using adapter mode..

here is an example of my code:

Dim q = From c In metaData.Contact
Where c.Orders.Count() = 0
Select c

return q.toList

When executed I get the following exception:

SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryConstructionException was unhandled Message=The property 'Count' isn't mapped to a field or database construct of entity type '...'. Did you mean to call an extension method instead? ('Count' vs. 'Count()') ? RuntimeBuild=12022009 RuntimeVersion=2.6.0.0 Source=SD.LLBLGen.Pro.LinqSupportClasses.NET35 ...

Its pretty straight forward but I am a newbie to llbl. Is this the proper way of doing this?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 12-Feb-2010 11:25:48   

Which runtime library build number are you using?

The runtime library version is obtainable by right-clicking the SD.LLBLGen.Pro.ORMSupportClasses.NETxy.dll in windows explorer and then by selecting properties and the version tab. The version is then enlisted at the top as the fileversion. It has the typical format as 2.0.0.YYMMDD, or starting in 2007, the format 2.0.YY.MMDD

Please do the same for the SD.LLBLGen.Pro.LinqSupportClasses... dll.

Thanks.

pt
User
Posts: 23
Joined: 24-Dec-2009
# Posted on: 12-Feb-2010 14:31:05   

SD.LLBLGen.Pro.ORMSupportClasses - 2.6.9.1202 SD.LLBLGen.Pro.LinqSupportClasses - 2.6.9.1106

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Feb-2010 05:53:42   

Reproduced. We will look into it.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 13-Feb-2010 13:59:45   

The problem is that the 'count' property on the collection shouldn't be used, the Count() extension method should be used. However it seems that the VB.NET compiler emits code which suggests a call to the Count property instead of a call to the Count() extension method.

We'll look into how this can be fixed / worked around. If you must, you could use a workaround like using our extension method CountColumn(e=>e._primarykeyfield_) but that's less ideal, so we'll look into why this appears even if you explicitly specified the () brackets (so which means you call the Count() extension method, not the Count property)

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 15-Feb-2010 10:56:44   

Man this is so utterly wrong by MS, I don't know where to begin... Even though you specify a call to an extension method, it still thinks it's a property call. It's even documented in the Count() extension method (which I really wonder about why that was done, to obscure the #fail in their compiler I guess).

The problem with mapping the Count property as a Count aggregate, is that it also matches in-memory list count access. I've to check whether that will work out ok. disappointed There's a workaround which currently fails (appending .AsQueryable to .Orders, so .Orders.AsQueryable.Count()) but which is easily addressed and which could help without modifying the pipeline a lot.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 15-Feb-2010 12:11:48   

I've added code which converts .Count access to .Count() inside the linq provider which now makes your query work. Let's hope the VB.NET compiler people haven't created more puddles of mud ...

Frans Bouma | Lead developer LLBLGen Pro
pt
User
Posts: 23
Joined: 24-Dec-2009
# Posted on: 15-Feb-2010 14:52:28   

Haha yeah thats what I was thinking, gotta love VB. I'll give it a try, thank you Otis!