How to OrderBy on a generic IEnumerable (IEnumerable<T>) using LINQ in C#?
- by Jeffrey
In my generic repository I have below method:
public virtual IEnumerable<T> GetAll<T>() where T : class
{
using (var ctx = new DataContext())
{
ctx.ObjectTrackingEnabled = false;
var table = ctx.GetTable<T>().ToList().AsReadOnly();
return table;
}
}
T is a Linq to Sql class and I want to be able to OrderBy on a particular property. Say if T has property name "SortOrder" then do OrderBy on this property. But I am not sure how I can achieve this. So I need some helps. Thank you!