Skip to content

Instantly share code, notes, and snippets.

@jonsagara
Created September 16, 2012 17:16
Show Gist options
  • Save jonsagara/3733293 to your computer and use it in GitHub Desktop.
Save jonsagara/3733293 to your computer and use it in GitHub Desktop.
IQueryable<T> Extensions
public static class LinqExtensions
{
public static IOrderedQueryable<TSource> OrderBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, bool isAscending)
{
return isAscending
? source.OrderBy(keySelector)
: source.OrderByDescending(keySelector);
}
public static IOrderedQueryable<TSource> ThenBy<TSource, TKey>(this IOrderedQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, bool isAscending)
{
return isAscending
? source.ThenBy(keySelector)
: source.ThenByDescending(keySelector);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment