Hi,
I need some help with a sorting problem.
In my DB I have the folowing relations: Order-Car-Dispatch-Address.
An order can contain 1-10 cars which contains 1-3 dispatches.
Each dispatch has a destination address (Rel. to Address table) and a driving sequence (1-3). Each car has at least 1 asociated dispatch and maximum 3.
The address table contains a "CustomerRefID" column.
What I want is to get a list of cars orderd by "Address.CustomerRefID". Since a car can have up to 3 dispatches (the dispatch has the relation to the Address table) I want to use the one with the higest driving sequence.
This is what I have until now:
RelationCollection relationsToUse = new RelationCollection();
IPredicateExpression filter = new PredicateExpression();
ISortExpression sorter = new SortExpression();
filter.Add(OrderFields.InvoiceDate >= fromInvoiceDate.Date);
filter.Add(OrderFields.InvoiceDate <= toInvoiceDate.Date);
filter.Add(OrderFields.CustomerID == CustomerID);
relationsToUse.Add(CarEntity.Relations.OrderEntityUsingOrderID);
relationsToUse.Add(OrderEntity.Relations.CustomerEntityUsingCustomerID);
relationsToUse.Add(CarEntity.Relations.DispatchEntityUsingCarID);
relationsToUse.Add(DispatchEntity.Relations.AddressEntityUsingDestinationAddressID);
sorter.Add(AddressFields.CustomerRefID | SortOperator.Ascending);
sorter.Add(OrderFields.InvoiceDate | SortOperator.Ascending);
sorter.Add(OrderFields.OrderID | SortOperator.Ascending);
CarCollection result = new CarCollection();
result.GetMulti(filter, 0, sorter, relationsToUse);
return result;
But it is not sorted the way I want since it does not use the right relation betwen dispatch and address.
What should I try?