internal static IQueryable CreateOrderByExpression(IOrderedDictionary parameters, IQueryable source, IDynamicQueryable queryable) { if (parameters != null && parameters.Count > 0) { //extract parameter values //extract the order by expression and apply it to the queryable string orderByExpression = GetOrderByClause(parameters.ToDictionary()); if (!String.IsNullOrEmpty(orderByExpression)) { return(queryable.OrderBy(source, orderByExpression)); } } return(source); }
internal static IQueryable CreateOrderByExpression(IOrderedDictionary parameters, IQueryable source, IDynamicQueryable queryable) { if (parameters != null && parameters.Count > 0) { //extract parameter values //extract the order by expression and apply it to the queryable string orderByExpression = GetOrderByClause(parameters.ToDictionary()); if (!String.IsNullOrEmpty(orderByExpression)) { return queryable.OrderBy(source, orderByExpression); } } return source; }
protected IQueryable ExecuteQueryExpressions(IQueryable source, QueryContext context) { if (source != null) { QueryCreatedEventArgs queryArgs = new QueryCreatedEventArgs(source); OnQueryCreated(queryArgs); source = queryArgs.Query ?? source; // Support the Dynamic Expression language used by LinqDataSource if (AutoGenerateWhereClause) { if (!String.IsNullOrEmpty(Where)) { throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, AtlasWeb.LinqDataSourceView_WhereAlreadySpecified, _owner.ID)); } source = QueryableDataSourceHelper.CreateWhereExpression(context.WhereParameters, source, _queryable); } else if (!String.IsNullOrEmpty(Where)) { source = _queryable.Where(source, Where, context.WhereParameters.ToEscapedParameterKeys(_owner)); } if (AutoGenerateOrderByClause) { if (!String.IsNullOrEmpty(OrderBy)) { throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, AtlasWeb.LinqDataSourceView_OrderByAlreadySpecified, _owner.ID)); } source = QueryableDataSourceHelper.CreateOrderByExpression(context.OrderByParameters, source, _queryable); } else if (!String.IsNullOrEmpty(OrderBy)) { source = _queryable.OrderBy(source, OrderBy, context.OrderByParameters.ToEscapedParameterKeys(_owner)); } string groupBy = GroupBy; if (String.IsNullOrEmpty(groupBy)) { if (!String.IsNullOrEmpty(OrderGroupsBy)) { throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, AtlasWeb.LinqDataSourceView_OrderGroupsByRequiresGroupBy, _owner.ID)); } } else { source = _queryable.GroupBy(source, groupBy, "it", context.GroupByParameters.ToEscapedParameterKeys(_owner)); if (!String.IsNullOrEmpty(OrderGroupsBy)) { source = _queryable.OrderBy(source, OrderGroupsBy, context.OrderGroupsByParameters.ToEscapedParameterKeys(_owner)); } } if (!String.IsNullOrEmpty(SelectNew)) { source = _queryable.Select(source, SelectNew, context.SelectParameters.ToEscapedParameterKeys(_owner)); } return(source); } return(source); }