I have a repository class that is very generic in its use and doesn’t refer to my tables specifically. Shown below is one of the functions to get all the items in a table. What I would like to do is to extend this so that the result can be ordered. Is there a way to pass in a predicate / expression or something similar?
public IQueryable<T> All<T>() where T : class
{
return _context.Set<T>().AsQueryable();
}
Simply use
Queryable.OrderBymethod on your all entities:If you want to add method with predicate:
BTW
DbSet<T>implementsIQueryable<T>, so you don’t need to callAsQueryable().