I want to run the following query:
SELECT DISTINCT ContactName, ContactEmail, COUNT(*) AS Bookings
FROM BookingList
GROUP BY ContactName, ContactEmail
HAVING (NOT (ContactEmail = '')) AND (COUNT(*) > 20)
ORDER BY COUNT(*) DESC
I can get it all apart from the filtering and sorting using the aggregate field using this code:
Dim MyContactList As New DataTable
Dim fields As New ResultsetFields(3)
fields.DefineField(BookingListFields.ContactName, 0)
fields.DefineField(BookingListFields.ContactEmail, 1)
fields.DefineField(BookingListFields.ContactEmail, 2, SD.LLBLGen.Pro.ORMSupportClasses.AggregateFunction.Count)
Dim filter As IPredicateExpression = New PredicateExpression
filter.Add(BookingListFields.ContactEmail <> "")
'filter.AddWithAnd
Dim sorter As ISortExpression = New SortExpression
'sorter.Add()
Dim GroupBy As IGroupByCollection = New GroupByCollection
GroupBy.Add(fields(0))
GroupBy.Add(fields(1))
Dim MyDynamicList As New TravBase.DaoClasses.TypedListDAO()
MyDynamicList.GetMultiAsDataTable(fields, MyContactList, 0, sorter, filter, Nothing, False, GroupBy, Nothing, 0, 0)
What do I need to add to my sorter and filter to sort and filter on the aggregate field COUNT(*) (Or in this case COUNT(ContactEmail))
I've searched the forums and the help without any joy so far...