I have this generic method:
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);
}
When I use it:
List<Person> people = repository.PaginateAndOrderByDesc<Person>(1,
30, x = > x.RegistrDate)
.ToList();
I get an error: "Unable to cast the type 'System.DateTime' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types."
How do I make that Generic function work with orderByDescending expression?