Hy, I have a question about if there would be another way to sort a collection that has lot's of data on a field that is on another Entity wich is in relation with my collection.The way I do it now is I am using a IComparer to sort.The problem is that is very slow...the way I am doing it now.I have also some code so you'd have a better undertanding how I am doing it.
I am using Sql Server 2005 and LLBL GEN Pro 2.5.
DateOfLastStatusComparer dateOfLastStatusComparer = new DateOfLastStatusComparer();
orders.Sort((int)SalesOrderFieldIndex.SalesOrderId, (GridSortDirection == "ASC") ? System.ComponentModel.ListSortDirection.Ascending : System.ComponentModel.ListSortDirection.Descending, dateOfLastStatusComparer);
Where orers is a SalesOrderCollection -and the this collection is in relation with the SalesOrderLogEntity .
And I needed to sort all the orders by the field LogDate in the SalesOrderLogEntity.
Here is the IComparer :
public class DateOfLastStatusComparer:IComparer<object>
{
#region IComparer Members
public int Compare(object x, object y)
{
try
{
int orderId1, orderId2;
int.TryParse(x.ToString(), out orderId1);
int.TryParse(y.ToString(), out orderId2);
SalesOrderEntity order1 = new SalesOrderEntity(orderId1);
SalesOrderEntity order2 = new SalesOrderEntity(orderId2);
if (order1.SalesOrderLog.Count > 0 && order2.SalesOrderLog.Count > 0)
return DateTime.Compare(order1.SalesOrderLog[order1.SalesOrderLog.Count - 1].LogDate, order2.SalesOrderLog[order2.SalesOrderLog.Count - 1].LogDate);
else
return 0;
}
catch (Exception e)
{
return 0;
}
}
#endregion
}
If you know a better idea to do this, so it would more efecient please reaply me.Thanks in advance.