/// <summary> /// Sort and paginate results /// </summary> /// <param name="queryable"></param> /// <param name="paginationQuery"></param> /// <typeparam name="TModel"></typeparam> /// <returns></returns> public static IQueryable <TModel> TransformBy <TModel>(this IQueryable <TModel> queryable, IPaginationQuery paginationQuery) { var pageSize = paginationQuery.PageSize > PaginationSettings.MaxPageSize ? PaginationSettings.MaxPageSize : paginationQuery.PageSize; if (!string.IsNullOrEmpty(paginationQuery.OrderBy)) { queryable = SortExpressionFactory.SortBy(queryable, paginationQuery.OrderBy); } queryable = queryable .Skip(pageSize * paginationQuery.Page) .Take(pageSize); return(queryable); }
/// <summary> /// To the query options. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="odataQueryOptions">The o data query options.</param> /// <returns>QueryOptions{``0}.</returns> public static QueryOptions <T> ToQueryOptions <T>(this ODataQueryOptions <T> odataQueryOptions) { if (odataQueryOptions == null) { return(null); } var nameResolver = new MemberNameResolver(); var selectFactory = new SelectExpressionFactory <T>(nameResolver, new RuntimeTypeProvider(nameResolver)); var filterFactiory = new FilterExpressionFactory(nameResolver, Enumerable.Empty <IValueExpressionFactory>()); var orderFactory = new SortExpressionFactory(nameResolver); return(new QueryOptions <T> { Top = odataQueryOptions.Top?.Value, Skip = odataQueryOptions.Skip?.Value, Select = !string.IsNullOrEmpty(odataQueryOptions.SelectExpand?.RawSelect) ? selectFactory.Create(odataQueryOptions.SelectExpand.RawSelect) : null, Expand = !string.IsNullOrEmpty(odataQueryOptions.SelectExpand?.RawExpand) ? odataQueryOptions.SelectExpand.RawExpand.Split(',').ToList() : null, OrderBy = !string.IsNullOrEmpty(odataQueryOptions.OrderBy?.RawValue) ? orderFactory.Create <T>(odataQueryOptions.OrderBy.RawValue) .Select( description => new SortDescription( description.KeySelector, (SortDirection)description.Direction)) .ToList() : null, Filter = !string.IsNullOrEmpty(odataQueryOptions.Filter?.RawValue) ? filterFactiory.Create <T>(odataQueryOptions.Filter.RawValue) : null }); }
public void FixtureSetup() { _factory = new SortExpressionFactory(new MemberNameResolver()); }