Hi Chuck,
I want to do something a little simpler that does not involve an expression. I simply need to return a date field for each record with a max ID field. I can't figure out the syntax.
You could use DynamicLists. See this example, it retrieves all the customers and the number of orders of each one:
// C#
ResultsetFields fields = new ResultsetFields(2);
fields.DefineField(CustomerFields.CustomerId, 0);
fields.DefineField(new EntityField2("NumberOfOrders",
new ScalarQueryExpression(OrderFields.OrderId.SetAggregateFunction(AggregateFunction.Count),
(CustomerFields.CustomerId == OrderFields.CustomerId))), 2);
DataTable results = new DataTable();
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchTypedList(fields, results, null);
With a little modification, this code return all customers and the last order date of each one.
// C#
ResultsetFields fields = new ResultsetFields(2);
fields.DefineField(CustomerFields.CustomerId, 0);
fields.DefineField(new EntityField2("NumberOfOrders",
new ScalarQueryExpression(OrderFields.OrderDate.SetAggregateFunction(AggregateFunction.Max),
(CustomerFields.CustomerId == OrderFields.CustomerId))), 2);
DataTable results = new DataTable();
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchTypedList(fields, results, null);
You can see this example in LLBLGenPro Help - Using generated code - Field expressions and aggregates - Scalar query expressions.
If you wish to use EntityClasses and have a customProperty that shows the lastDateOrdered, you can extend the Fields of an Entity. Please read http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=10287
Was this helpful? Can we assist you more on this?