Print Page | Close Window

Error when using SubQuery and OrderBy

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=599
Printed Date: 03-Sep-2025 at 7:15am


Topic: Error when using SubQuery and OrderBy
Posted By: johneevo
Subject: Error when using SubQuery and OrderBy
Date Posted: 10-Dec-2007 at 6:49am
I'm receiving a "Failed to compare two elements in the array." error when using a query that has a subquery and order by clauses. I am ordering by 5 columns but the one that is causing the problem is an int32 column that contains NULLs.

If I suppress query inversion I do not get an error but the data is not sorted correctly.

If I leave query inversion on and do not sort by the problem column, then I do not get an error and the data is sorted correctly.

The inner exception that I get with the above mentioned query is:
"At least one object must implement IComparable."

Let me know if you need more info on this error.



Replies:
Posted By: davidklitzke
Date Posted: 10-Dec-2007 at 8:56am
This appears to be a .NET problem, not a DevForce problem.  If you search the web, you can find a few links to articles which discuss this problem.
 
Try:
 
http://www.informit.com/articles/article.aspx?p=25352&seqNum=4&rl=1 - http://www.informit.com/articles/article.aspx?p=25352&seqNum=4&rl=1
 
http://odetocode.com/Articles/203.aspx - http://odetocode.com/Articles/203.aspx
 
http://forums.asp.net/p/191214/419345.aspx#419345 - http://forums.asp.net/p/191214/419345.aspx#419345
 
Perhaps, one of your Entities needs to override IComparable (as shown in the example below):
 
 public override int CompareTo(Object pObject) {
   Employee emp = pObject as Employee;
   if (emp == null) return 1;
   return this.LastName.CompareTo(emp.LastName);
  }
 



Print Page | Close Window