CSLA.NET > 3.5.1: Bug when using cast in linq against BusinessListCSLA.NET > 3.5.1: Bug when using cast in linq against BusinessList
Old forum URL: forums.lhotka.net/forums/t/5197.aspx
Patrick posted on Tuesday, August 05, 2008
Hi,
Using a cast in a linq query against a CSLA results in an exception in LinqBindingList.ItemShouldBeInList():
1) This works:
var results = from LookupValues in _lookupList
where LookupValues.LookupGroup.ToLower().Equals(LookupGroup.ToLower())
select LookupValues;
2) This doesn't work:
var results = from LookupValues l in _lookupList
where l.LookupValues.LookupGroup.ToLower().Equals(LookupGroup.ToLower())
select l;
3) This doesn't work either:
var results = from l in _lookupList.Cast<LookupValues>()
where l.LookupValues.LookupGroup.ToLower().Equals(LookupGroup.ToLower())
select l;
Example 2) + 3) lead to the whereExpression == null in SetFilterByExpression in LinqBindingList
---------------
private void SetFilterByExpression(Expression expression)
{
InnermostWhereFinder whereFinder = new InnermostWhereFinder();
MethodCallExpression whereExpression = whereFinder.GetInnermostWhere(expression);
if (whereExpression == null) return;
/// ....
}
-----------
which in turn throws an exception in ItemShouldBeInList in LinqBindingList
-------------
private bool ItemShouldBeInList(T item)
{
InnermostWhereFinder whereFinder = new InnermostWhereFinder();
MethodCallExpression whereExpression = whereFinder.GetInnermostWhere(_expression);
Expression<Func<T, bool>> whereBody = (Expression<Func<T, bool>>)((UnaryExpression)(whereExpression.Arguments[1])).Operand;
/// ....
}
------------
Thanks for looking into it,
Patrick
RockfordLhotka replied on Tuesday, August 05, 2008
Thanks, we'll look into it.AaronErickson replied on Wednesday, August 06, 2008
FYI, I have it down to CreateQuery in the CslaQueryProvider, which needs to handle the cast case similar to how the OfType case gets handled. Fix should be in the works with an associated unit test by end of day today.
AaronErickson replied on Wednesday, August 06, 2008
Also, case 2 turns into case 3 at the expression evaluator level, so fixing one fixes the other.AaronErickson replied on Wednesday, August 06, 2008
I have committed bits to the trunk that should have this fixed.
Patrick replied on Wednesday, August 06, 2008
I'm impressed how quickly you fixed this :)
Might be good to back port it to 3.5.1 in subversion as well as quite a few people might not be using 3.6.x yet.
Thanks a lot,
Patrick
RockfordLhotka replied on Wednesday, August 06, 2008
3.5.1 is released, so this will be in 3.5.2. I think that’s
where Aaron put the fix – we’ll have to merge it into 3.6 as well.
Rocky
From: Patrick
[mailto:cslanet@lhotka.net]
Sent: Wednesday, August 06, 2008 3:32 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CSLA.NET > 3.5.1: Bug when using cast in
linq against BusinessList
I'm impressed how quickly you fixed this :)
Might be good to back port it to 3.5.1 in subversion as well as quite a few
people might not be using 3.6.x yet.
Thanks a lot,
Patrick
Copyright (c) Marimer LLC