my application has the following code to add a ToSortedList extension method on any IEnumberable:
public class SortedList<T, TResult> : List<T> {
public SortedList(IEnumerable<T> source, Expression<Func<T, TResult>> sortBy, SortDirection sortDirection) {
Initialize(source is IQueryable<T> ? source as IQueryable<T> : source.AsQueryable(), sortBy, sortDirection);
}
protected void Initialize(IQueryable<T> source, Expression<Func<T, TResult>> sortBy, System.Web.UI.WebControls.SortDirection sortDirection) {
AddRange(sortDirection == SortDirection.Ascending ? source.OrderBy(sortBy) : source.OrderByDescending(sortBy));
}
}
public static class SortingExtensions {
public static SortedList<T, TResult> ToSortedList<T, TResult>(this IEnumerable<T> source, Expression<Func<T, TResult>> sortBy, SortDirection sortDirection) {
return new SortedList<T, TResult>(source, sortBy, sortDirection);
}
}
In the old LINQ provider (on top of NHibernate 2.1) i could then say:
session.Linq<Article>().ToSortedList(a => a.Date, SortDirection.Ascending);
However using the new in-built LINQ provider in NHibernate 3 (change Linq to Query above) this does not work and the following error is thrown:
"Specified method is not supported." - within the Initialize method
I'd really appreciate it if someone could show me how this could be done.