Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  




           


Sort by custom column name in Entity Framework
You can sort by a custom (string) column name and direction (i.e. ID DESC) in Entity Framework by adding the DynamicQueryable library and changing OrderBy to return an IOrderedQueryable instead of Queryable (LINQ used Queryable, but EF wants IOrderedQueryable):

public static IOrderedQueryable OrderBy (this IQueryable source, string ordering, params object[] values)
{
return (IOrderedQueryable )OrderBy((IQueryable)source, ordering, values);
}

The DynamicQueryable class can be found at: https://msdn.microsoft.com/en-us/vstudio/bb894665.aspx
In: LinqSamples/DynamicQuery/DynamicQuery/Dynamic.cs (copy to your project)

Created By: amos 10/14/2015 12:10:05 PM
Updated: 10/14/2015 12:12:04 PM