private static IOrderedQueryable <TSource> OrderByWithDefault <TSource>(this IQueryable <TSource> source, string propertyName, bool isAscending, params string[] thenByPropertyNames) { if (propertyName.Trim(',').Contains(",")) { var names = propertyName .Split(_splitOnComma, StringSplitOptions.RemoveEmptyEntries) .Union(thenByPropertyNames); propertyName = names.First(); thenByPropertyNames = names.Skip(1).ToArray(); } var orderByProperty = new OrderByProperty(propertyName, isAscending); var returnValue = _PropertyCache <TSource> .OrderByPropAndDirection(source, orderByProperty); foreach (var thenByPropertyString in thenByPropertyNames) { returnValue = _PropertyCache <TSource> .ThenByPropAndDirection(returnValue, new OrderByProperty(thenByPropertyString, isAscending)); } return(returnValue); }
public static IOrderedQueryable <TSource> ThenByPropAndDirection(IOrderedQueryable <TSource> source, OrderByProperty property) { return(property.IsAscending ? PropertyCache <TSource, IQueryable <TSource>, IOrderedQueryable <TSource> > .ThenBy(source, property.PropertyName) : PropertyCache <TSource, IQueryable <TSource>, IOrderedQueryable <TSource> > .ThenByDescending(source, property.PropertyName)); }
public static IOrderedEnumerable <TSource> OrderByPropAndDirection(IEnumerable <TSource> source, OrderByProperty property) { return(property.IsAscending ? PropertyCache <TSource, IEnumerable <TSource>, IOrderedEnumerable <TSource> > .OrderBy(source, property.PropertyName) : PropertyCache <TSource, IEnumerable <TSource>, IOrderedEnumerable <TSource> > .OrderByDescending(source, property.PropertyName)); }