Possible Duplicate:
Dynamic LINQ OrderBy
I'm trying to create a dynamic sorting to Iqueryable.
So bellow you can see that I am following some examples I see here in stackoverflow.
var query = dalSession.Query<T>();
var res = (from x in query orderby Extensions.Sort<T>(query, "FirstName") select x).Skip((paging.CurrentPageRecord)).Take(paging.PageSize);
public static class Extensions
{
public static IQueryable<T> Sort<T>(this IQueryable<T> query,
string sortField)
{
return query.OrderByDescending(s => s.GetType()
.GetProperty(sortField));
}
}
This is the exception that I get:
System.Linq.IQueryable
1[Partners.BusinessObjects.Affiliate] Sort[Affiliate](System.Linq.IQueryable
1[Partners.BusinessObjects.Affiliate], System.String)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: System.Linq.IQueryable`1[Partners.BusinessObjects.Affiliate] Sort[Affiliate](System.Linq.IQueryable`1[Partners.BusinessObjects.Affiliate], System.String)