【发布时间】:2012-11-06 13:36:33
【问题描述】:
可能重复:
Dynamic LINQ OrderBy
我正在尝试为 Iqueryable 创建动态排序。
因此,您可以在下面看到我正在关注我在 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));
}
}
这是我得到的例外:
System.Linq.IQueryable
1[Partners.BusinessObjects.Affiliate] Sort[Affiliate](System.Linq.IQueryable1[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)
【问题讨论】:
标签: c# .net dynamic expression iqueryable