public static IOrderedQueryable <TSource> ThenBy <TSource>(this IOrderedQueryable <TSource> source, string field, bool ascending = true) { if (string.IsNullOrWhiteSpace(field)) { return(source); } if (field.Contains(" ")) { var chunks = field.Split(' '); if (chunks.Length == 2) { field = chunks[0]; ascending = string.Equals(chunks[1], "asc", StringComparison.InvariantCultureIgnoreCase); } } var lambda = source.GetLambda(field); if (!ascending) { return(source.ThenByDescending(lambda)); } return(source.ThenBy(lambda)); }