InvalidCastException with boolean field in an any clause

Posts   
 
    
TomDog
User
Posts: 623
Joined: 25-Oct-2005
# Posted on: 18-Jan-2011 09:44:07   

This query in LINQPad against Northwind.

Product.Any(p => p.Discontinued)

gives

InvalidCastException: Unable to cast object of type 'SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.EntityFieldExpression' to type 'SD.LLBLGen.Pro.LinqSupportClasses.ExpressionClasses.FilterExpression'.

but this

Product.Any(p => p.Discontinued == true)

is fine as is

Product.Count(p => p.Discontinued)

What gives?

linq 3.0.11.113 and orm support 3.0.10.1201

Jeremy Thomas
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Jan-2011 11:26:46   

I think because Count() neads a field, but Any() expects an expression.

TomDog
User
Posts: 623
Joined: 25-Oct-2005
# Posted on: 18-Jan-2011 11:30:22   

Walaa wrote:

I think because Count() neads a field, but Any() expects an expression.

No they both take the same parameter System.Linq.Expressions.Expression<Func<TSource,bool>> predicate

Jeremy Thomas
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 18-Jan-2011 12:44:17   

Bug

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 18-Jan-2011 18:07:04   

Fixed in attached dll.

the following bugs were fixed in this dll: Linq: A boolean predicate in an All/Any call using a not (e.g. .Any(p=>!p.Discontinued)) failed. Linq: A boolean predicate in an All/Any call without comparison with true/false failed. Linq: Testing for NULL on an entity in a projection combined with a conditional expression (e.g. IIF() / ?: ) failed with an exception.

Frans Bouma | Lead developer LLBLGen Pro
TomDog
User
Posts: 623
Joined: 25-Oct-2005
# Posted on: 19-Jan-2011 00:17:51   

Otis wrote:

Fixed in attached dll.

Thanks simple_smile

Jeremy Thomas