Is this a bug or am I doing something wrong

Posts   
 
    
younghov
User
Posts: 8
Joined: 14-Nov-2006
# Posted on: 15-Dec-2006 13:39:36   

Hi,

I have code that looks like the following...

ParentCollection parentCollection= new ParentCollection (); try { parentCollection.GetMultiManyToOne(grandParentEntity);

                foreach (Parent parent in parentCollection)
                {
                    ChildCollection children= new ChildCollection();

                    IPredicateExpression filter = new PredicateExpression();
                    filter.Add(PredicateFactory.CompareValue(ChildFieldIndex.ParentID, ComparisonOperator.Equal, parent.ParentID));
                    children.GetMulti(filter);

                    double maxAge = (double)children.GetScalar(ChildFieldIndex.Age, AggregateFunction.Max);
                }
             }

.... .... etc

I keep getting a maxAge value equal to the MAX of ALL children. In other words, it looks like my filter is being ignored. Whats wierd is that the children count is correct.

Am I using the MAX aggregate correctly or is this a bug in LLBLGen? I'm using version 1.0.2005.1

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-Dec-2006 14:16:07   

The filter was not supplied to the GetScalar call. You only used the filter in the first query "children.GetMulti(filter);"

GetScalar() should have other overloads that accept a filter.

younghov
User
Posts: 8
Joined: 14-Nov-2006
# Posted on: 15-Dec-2006 14:33:53   

Walaa wrote:

The filter was not supplied to the GetScalar call. You only used the filter in the first query "children.GetMulti(filter);"

GetScalar() should have other overloads that accept a filter.

Thanks Walaa, that works great now. I was under the impression that since the children collection was already filtered, there was no need for me to re-filter it just to perform a MAX.

I'm sure there's a good reason behind it though.

Thanks! simple_smile

By the way, while waiting for your response, I decided to just manually loop through the children collection and figure out the MAX value that way instead.

Ironically, now that I think about it, since the children collection is already filtered, I might as well save one DB call by keeping the for-loop instead of using GetScalar(...). What do you think?