How to OrderBy on a generic IEnumerable (IEnumerable<T>) using LINQ in C#?

Posted by Jeffrey on Stack Overflow See other posts from Stack Overflow or by Jeffrey
Published on 2010-05-05T06:05:05Z Indexed on 2010/05/05 6:08 UTC
Read the original article Hit count: 172

Filed under:
|
|
|

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!

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ