我有这个通用方法:
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表达式一起工作呢?