Wednesday, April 29, 2009

Distinct with OrderBy operators in LINQ

Another day, another challenge.


I have to retrieve a set of distinct data rows that must be ordered by some criteria.
My problem was that first I applied OrderBy and then Distinct operator. After applying Distinct operator data ordering disappeared somehow.
The problem was that Distinct operator does not preserve ordering so you must place OrderBy operator after it. The same is valid for Union and Concat operators.


There is a good post describing this problem in detail that could be found here.


Hope this helps someone.

Regards,
Oleh

No comments: