public static IQueryable <T> OrderBy <T>(this IQueryable <T> source, params ISorting[] sortings) { IEntitySorter <T> sorter = null; if (sortings != null) { foreach (var sorting in sortings) { if (sorter == null) { sorter = sorting.Ascending ? EntitySorter <T> .OrderBy(sorting.ColumnName) : EntitySorter <T> .OrderByDescending(sorting.ColumnName); } else { sorter = sorting.Ascending ? sorter.ThenBy(sorting.ColumnName) : sorter.ThenByDescending(sorting.ColumnName); } } return(sorter != null?sorter.Sort(source) : source); } return(source); }
public IOrderedQueryable <T> Sort(IQueryable <T> col) { var sorted = _baseSorter.Sort(col); return(_direction == SortDirection.Asc ? sorted.ThenBy(_keySelector) : sorted.ThenByDescending(_keySelector)); }
/// <summary> /// Sorts the specified collection. /// </summary> /// <param name="collection"> /// The collection. /// </param> /// <returns> /// An <see cref="IOrderedEnumerable{TEntity}" />. /// </returns> public IOrderedQueryable <TEntity> Sort(IQueryable <TEntity> collection) { IOrderedQueryable <TEntity> sortedCollection = _baseSorter.Sort(collection); if (_sortDirection == SortDirection.Ascending) { return(sortedCollection.ThenBy(_keySelector)); } return(sortedCollection.ThenByDescending(_keySelector)); }
public IList <TEntity> List(IEntityFilter <TEntity> filter = null, IEntitySorter <TEntity> sorter = null, int?page = null, int?pageSize = null, IEntityLoader <TEntity> loader = null) { if ((page.HasValue || pageSize.HasValue) && sorter == null) { throw new ArgumentException("You have to define a sorting order if you specify a page or pageSize! (IEntitySorter was null)"); } if (page.HasValue && !pageSize.HasValue) { throw new ArgumentException("You have to define a pageSize if you specify a page!"); } var entities = Entities; if (filter != null) { entities = filter.Filter(entities); } if (sorter != null) { entities = sorter.Sort(entities); } if (page != null) { entities = entities.Skip(pageSize.Value * page.Value); } if (pageSize != null) { entities = entities.Take(pageSize.Value); } entities = entities.InterceptWith(new QueryableEntitiesVisitor()); if (loader != null) { return(loader.Load(entities)); } return(entities.ToList()); }