【发布时间】:2014-04-21 17:23:55
【问题描述】:
我有这个通用方法:
public IQueryable<TEntity> PaginateAndOrderByDesc<TEntity>(int pageIndex, int pageSize, Expression<Func<TEntity, object>> orderByDescending)
where TEntity : class, IContextEntity
{
int numberOfRecordsToSkip = (pageIndex - 1) * pageSize;
return context.Set<TEntity>().OrderByDescending(orderByDescending).Skip(numberOfRecordsToSkip).Take(pageSize);
}
当我使用它时:
List<Person> people = repository.PaginateAndOrderByDesc<Person>(1,
30, x = > x.RegistrDate)
.ToList();
我收到一个错误:“无法将类型 'System.DateTime' 转换为类型 'System.Object'。LINQ to Entities 仅支持转换 EDM 基元或枚举类型。”
如何使该通用函数与 orderByDescending 表达式一起使用?
【问题讨论】:
标签: c# linq entity-framework linq-to-entities