If you use just Func<Paste, object>
- you get overload of OrderBy
that retrieves all entites to memory and orders them. For getting more performance I would recommend you using Expression<T>
which would be translated in SQL and run on db side:
EDIT: Also you could make your method generic for omiting this:
NotSupportedException: Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types.
public IEnumerable<Paste> GetPastes<TOrderKey>(int page, string username,
Expression<Func<Paste, TOrderKey>> sortOrder)
{
// code from the question
}
Note that the way you call this method won't change because of type inference:
m_DAL.GetPastes(page, userName, x => x.ID).ToList<Paste>();