I'm currently testing the operator overloads I've implemented in the 1.0.2005.1 code (which I hope to have finished later this week if I can cram in all the little things still on the list). Operator overloads are used for creating expressions, sortclauses and predicate expressions. Furthermore I've added utility methods to EntityField(2) which allow you to chain commands together when setting object alias, aggregate function and expression on a field.
Also added are utility classes which produce an EntityField(2) object with a static method.
I've based some of the things on the ideas expressed by louthy here:
http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3460
ok, here's some code in the old style:
// SUM((UnitPrice*Quantity)-(UnitPrice*Quantity*Discount/100)) / SUM(Quantity) FROM [Order Details]
// UnitPrice * Quantity
IExpression eP1 = new Expression(EntityFieldFactory.Create(OrderDetailsFieldIndex.UnitPrice), ExOp.Mul, EntityFieldFactory.Create(OrderDetailsFieldIndex.Quantity));
// (UnitPrice * Quantity) * Discount
IExpression eP2 = new Expression(eP1, ExOp.Mul, EntityFieldFactory.Create(OrderDetailsFieldIndex.Discount));
// ((UnitPrice * Quantity) * Discount) / 100
IExpression eP3 = new Expression(eP2, ExOp.Div, 100);
// (UnitPrice * Quantity)-((UnitPrice * Quantity) * Discount) / 100
IExpression eP4 = new Expression(eP1, ExOp.Sub, eP3);
// sum((UnitPrice * Quantity)-((PrecioLocal * Quantity) * Discount) / 100)
IEntityField2 op1=EntityFieldFactory.Create(OrderDetailsFieldIndex.UnitPrice);
op1.ExpressionToApply=eP4;
op1.AggregateFunctionToApply=AggregateFunction.Sum;
// sum(Quantity)
IEntityField2 op2=EntityFieldFactory.Create(OrderDetailsFieldIndex.Quantity);
op2.AggregateFunctionToApply=AggregateFunction.Sum;
// sum((UnitPrice * Quantity)-((UnitPrice * Quantity) * Discount) / 100) / sum(Quantity)
IExpression expRes=new Expression(op1, ExOp.Div, op2);
IPredicate filter = PredicateFactory.CompareValue(OrderDetailsFieldIndex.OrderId, ComparisonOperator.Equal, 10254);
object r=adapter.GetScalar(EntityFieldFactory.Create(OrderDetailsFieldIndex.UnitPrice), expRes, AggregateFunction.None, filter);
Assert.AreEqual(7.88685265796607, r);
and this is the new style:
IExpression expOp1 = ((OrderDetailsFields.UnitPrice * OrderDetailsFields.Quantity) -
(OrderDetailsFields.UnitPrice * OrderDetailsFields.Quantity * OrderDetailsFields.Discount / 100));
EntityField2 op1 = OrderDetailsFields.UnitPrice.SetAggregateFunction(AggregateFunction.Sum).SetExpression(expOp1);
IExpression scalarExpression = op1 / OrderDetailsFields.Quantity.SetAggregateFunction(AggregateFunction.Sum);
IPredicate filter = (OrderDetailsFields.OrderId == 10254);
object r=adapter.GetScalar(OrderDetailsFields.UnitPrice, scalarExpression, AggregateFunction.None, filter);
Assert.AreEqual(7.88685265796607, r);
it can even be formulated shorter but you get the idea
VB.NET on .NET 1.x can't use this, as VB.NET .NET 1.x doesn't support operator overloads, though they can use and have the field utility classes which produce a field, and the utility methods on EntityField(2). People who use VB.NET for .NET 2.0 will be able to use this.
Ok, back to testing.
(ps: this is completely build on top of the current system with predicate objects, predicate expression object etc. etc., so your existing code will keep on working, there is now another, more easier way to write the same code, and you can mix the two as well, if you like )