Documentation code error?

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 02-Jan-2007 06:35:03   

In the **How Do I **section (newest build V2)

In the **

How do I get the MAX(Order.ShippingDate - Order.OrderDate) value from a customer's orders ?**

this example code fails as the third parameter in the GetScalar() expects an Aggregate function:


OrderCollection orders = new OrderCollection();
int maxValue = (int)orders.GetScalar(OrderFieldIndex.OrderId, (OrderFields.ShippedDate - OrderFields.OrderDate), 
    (OrderFields.CustomerId == _customerId));

If it's changed to this, it compiles.


OrderCollection orders = new OrderCollection();
int maxValue = (int)orders.GetScalar(OrderFieldIndex.OrderId, (OrderFields.ShippedDate - OrderFields.OrderDate), 
    AggregateFunction.Max);

Am I correct in that assumption or am I doing something wrong?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Jan-2007 06:54:01   

Yeah I think you are right, it's mising from the SelfServicing code C# & VB.NET 2005 examples.

Good Catch.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 02-Jan-2007 10:09:25   

Though, that's not the same call, as that last one doesn't filter on the customerid in the orders, so it will return the max of ALL orders, not the max of the orders of a given customer. Though indeed the code should compile wink

The right code is:


OrderCollection orders = new OrderCollection();
int maxValue = (int)orders.GetScalar(OrderFieldIndex.OrderId, (OrderFields.ShippedDate - OrderFields.OrderDate), AggregateFunction.Max, (OrderFields.CustomerId == _customerId));

using method: public object GetScalar(OrderFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter)

Frans Bouma | Lead developer LLBLGen Pro