CSLA 3.8.2 Linq to CSLA OrderBy Extension method not using Comparer

CSLA 3.8.2 Linq to CSLA OrderBy Extension method not using Comparer

Old forum URL: forums.lhotka.net/forums/t/9487.aspx

justin.fisher posted on Thursday, September 09, 2010

I am trying to filter and sort the entries stored in an Editable Child List class using the following code:

(from entry in ((MessageSubqueueList) Parent).Entries
 where entry.SubqueueId == this.ID
 select entry).OrderBy(e => e, new EntryComparer());

I have put a break point in the EntryComparer code and it is never being called.  I can do simply sorting by specifying a different key such as ...OrderBy(e => e.DeliveryOrder); and that works fine.  I had the entries implemented IComparable and that too seems to work fine but any attempt to pass in a comparer seem to be ignored by Linq To CSLA. 

I put the entries in a List<Entry> instance and called an OrderBy(e => e, new EntryComparer) and that works as expected.  So it would appear to be something going on with Linq To CSLA.

We were hoping that we could write the code so that the comparer could be swapped out based on the situation but right now with Linq To CSLA ignoring the comparer that is not possible.  I attempted to debug into the Linq To CSLA code but there is a lot of plumbing in there that I don't quite understand.

Does anyone have any ideas as to why this is not working?

RockfordLhotka replied on Thursday, September 09, 2010

This sort of issue is a reason why all this functionality was removed in CSLA 4. The level of complexity involved in what amounted to reimplementing LINQ to Objects is ridiculous, and the benefits don't match the cost.

The workaround for any 3.8 issues is to use a ToList() on the source collection, thereby bypassing the old LINQ to CSLA functionality, so you get pure LINQ to Objects behaviors.

Copyright (c) Marimer LLC