Upadate:
I have prepared a generic function for capturing database rows for generation the listing. My method is exactly like this.
public class GenericDataAccess<TEntity> : IGenericRepository<TEntity> where TEntity : class
{
internal ELearningDBContext ELearningDBContext;
internal DbSet<TEntity> ELearningDBSet;
public GenericDataAccess(ELearningDBContext context)
{
this.ELearningDBContext = context;
this.ELearningDBSet = context.Set<TEntity>();
}
public virtual PagingModel<TEntity> GetAllPaged(int pagesize, NameValueCollection queryString)
{
return ELearningDBSet.AsQueryable().ToList();
}
}
Here I am facing a problem to sort this list. Because the TEntity
is changing time to time. However, I have a common field in every Entity
named Id
. So I want to sort each and every model by Id
in descending
order.
I have tried this way. But it was not effective, moreover, it's generating an exception.
ELearningDBSet.AsQueryable()..OrderByDescending(i=>typeof(TEntity).GetProperty("Id")).ToList();
I have gone through these questions Q1, Q2, Q3, Q4. However, these were not effective. I prefer C#
code. Any kind of perfect solution is highly appreciated. Thank you.