The threads you link to is about sorting in a datagrid, but I can't find anything about sorting a view.
My problem is that I get a DispatchCollection from DB. This collectin is split in 5 collections and one of these collections should be sorted difrently than the other 4 (they use the sortign from the GetMulti).
Since I can't sort the DispatchCollection I have to sort the View of the DispatchCollection, but, as I wrote earlier, I want to sort using related fields. I have read the thread you linked to but I'm afraid I need more help.
This is the code that gets the DispatchCollection
IPredicateExpression filter = new PredicateExpression();
ISortExpression sort = new SortExpression();
IPrefetchPath prefetch = new PrefetchPath((int)EntityType.DispatchEntity);
PrefetchPathElement prefetchDestinationAddressZipCode = (PrefetchPathElement)AddressEntity.PrefetchPathZipCode;
PrefetchPathElement prefetchPickupAddressZipCode = (PrefetchPathElement)AddressEntity.PrefetchPathZipCode;
filter.Add(DispatchFields.CompletedDate == DBNull.Value);
if (dispatchPickupDateFrom.HasValue)
filter.AddWithAnd(DispatchFields.PickupDate >= dispatchPickupDateFrom.Value);
if (dispatchPickupDateTo.HasValue)
filter.AddWithAnd(DispatchFields.PickupDate <= dispatchPickupDateTo.Value);
prefetchDestinationAddressZipCode.SubPath.Add(ZipCodeEntity.PrefetchPathAreaDefinition ).SubPath.Add(AreaDefinitionEntity.PrefetchPathRegion);
prefetchDestinationAddressZipCode.SubPath.Add(ZipCodeEntity.PrefetchPathCountry);
prefetch.Add(DispatchEntity.PrefetchPathAddressDestination).SubPath.Add(prefetchDestinationAddressZipCode);
prefetchPickupAddressZipCode.SubPath.Add(ZipCodeEntity.PrefetchPathAreaDefinition ).SubPath.Add(AreaDefinitionEntity.PrefetchPathRegion);
prefetchPickupAddressZipCode.SubPath.Add(ZipCodeEntity.PrefetchPathCountry);
prefetch.Add(DispatchEntity.PrefetchPathAddressPickup).SubPath.Add(prefetchPickupAddressZipCode);
prefetch.Add(DispatchEntity.PrefetchPathCar).SubPath.Add(CarEntity.PrefetchPathCarModel ).SubPath.Add(CarModelEntity.PrefetchPathCarManufacturer);
prefetch.Add(DispatchEntity.PrefetchPathDispatchList).SubPath.Add(DispatchListEntity.PrefetchPathDriver);
sort.Add(DispatchFields.PickupDate | SortOperator.Ascending);
DispatchCollection result = new DispatchCollection();
result.GetMulti(filter, 0, sort, null, prefetch);
return result;
This is where I sort the DispatchCollecting (after splitting the "original" collection into 5 collections)
public static DispatchCollection SortAbroadDispatchList(DispatchCollection dispatchCollection)
{
IEntityView view = dispatchCollection.DefaultView;
ISortExpression sort = new SortExpression();
sort.Add(new SortClause(ZipCodeFields.ZipCode, SortOperator.Ascending));
view.Sorter = sort;
DispatchCollection result = new DispatchCollection();
foreach (DispatchEntity entity in view)
{
result.Add(entity);
}
return result;
}
As I wrote in message #1 the relation is Dispatch - Address - ZipCode - Country. Each dispatch has 2 relations to Address (PickupAddress ad DestinationAddress)