I have a website that used to use a lot of methods to get lists from my data context. I have recently began changing those to generic methods to cut down on code; however, a lot of the methods have me doing an OrderBy before I return the list. This is what I'm using for my generic method already.
public List<TEntity> GetObjects<TEntity>()
where TEntity : class
{
return this.dataContext.Set<TEntity>().ToList();
}
I would like, if it's possible, to have something similar to this, where I can pass in the name of the variable I would like the list to be sorted by, and use that to sort the list before the generic method returns it. Maybe something along the lines of:
public List<TEntity> GetObjects<TEntity>(string orderedVariable)
where TEntity : class
{
// Code to get information about the property of the class
return this.dataContext.Set<TEntity>()OrderBy(// Code to sort the list).ToList();
}