internal OrderByQueryOption(string rawValue, ODataQueryContext context, string applyRaw) { if (context == null) { throw Error.ArgumentNull("context"); } if (String.IsNullOrEmpty(rawValue)) { throw Error.ArgumentNullOrEmpty("rawValue"); } if (applyRaw == null) { throw Error.ArgumentNullOrEmpty("applyRaw"); } Context = context; RawValue = rawValue; Validator = OrderByQueryValidator.GetOrderByQueryValidator(context); _queryOptionParser = new ODataQueryOptionParser( context.Model, context.ElementType, context.NavigationSource, new Dictionary <string, string> { { "$orderby", rawValue }, { "$apply", applyRaw } }); _queryOptionParser.ParseApply(); }
public IQueryable DoQuery(string value) { string queryOption = "$apply"; var data = TestDataSource.CreateData(); ODataQuerySettings settings = new ODataQuerySettings() { PageSize = 2000, HandleNullPropagation = HandleNullPropagationOption.False }; var model = TestModelBuilder.CreateModel(new Type[] { typeof(Category), typeof(Product), typeof(Sales) }); var context = new ODataQueryContext(model, typeof(Sales), new ODataPath(new ODataPathSegment[] { new EntitySetPathSegment("Sales") })); IEdmNavigationSource source = model.FindDeclaredEntitySet("Sales"); var parser = new ODataQueryOptionParser(model, model.FindDeclaredType("System.Web.OData.Aggregation.Tests.Common.Sales"), source, new Dictionary <string, string>() { { queryOption, value } }); var applyClause = parser.ParseApply(); var filterClause = applyClause.Transformations.First().Item2 as ApplyFilterClause; var filter = new FilterImplementation() { Context = context }; return(filter.DoFilter(data, filterClause, settings, parser)); }
private ApplyClause CreateApplyNode(string clause, IEdmModel model, Type entityType) { IEdmEntityType productType = model.SchemaElements.OfType <IEdmEntityType>().Single(t => t.Name == entityType.Name); Assert.NotNull(productType); // Guard IEdmEntitySet products = model.EntityContainer.FindEntitySet("Products"); Assert.NotNull(products); // Guard ODataQueryOptionParser parser = new ODataQueryOptionParser(model, productType, products, new Dictionary <string, string> { { "$apply", clause } }); return(parser.ParseApply()); }
private static void GetGroupByParams(string value, out IQueryable data, out ODataQueryContext context, out ODataQuerySettings settings, out ApplyGroupbyClause groupByClause, out DefaultAssembliesResolver assembliesResolver, out GroupByImplementation groupByImplementation, out Type keyType, out IEnumerable <LambdaExpression> propertiesToGroupByExpressions) { string queryOption = "$apply"; data = TestDataSource.CreateData(); settings = new ODataQuerySettings() { PageSize = 2000, HandleNullPropagation = HandleNullPropagationOption.False }; var _settings = settings; var model = TestModelBuilder.CreateModel(new Type[] { typeof(Category), typeof(Product), typeof(Sales) }); context = new ODataQueryContext(model, typeof(Sales), new ODataPath(new ODataPathSegment[] { new EntitySetPathSegment("Sales") })); var _context = context; IEdmNavigationSource source = model.FindDeclaredEntitySet("Sales"); var parser = new ODataQueryOptionParser(model, model.FindDeclaredType("System.Web.OData.Aggregation.Tests.Common.Sales"), source, new Dictionary <string, string>() { { queryOption, value } }); var applyCaluse = parser.ParseApply(); groupByClause = applyCaluse.Transformations.First().Item2 as ApplyGroupbyClause; assembliesResolver = new DefaultAssembliesResolver(); var _assembliesResolver = assembliesResolver; groupByImplementation = new GroupByImplementation() { Context = context }; keyType = groupByImplementation.GetGroupByKeyType(groupByClause); var entityParam = Expression.Parameter(context.ElementClrType, "$it"); propertiesToGroupByExpressions = groupByClause.SelectedPropertiesExpressions.Select( exp => FilterBinder.Bind(exp, _context.ElementClrType, _context.Model, _assembliesResolver, _settings, entityParam)); }
public QueryDescription <T> Parse <T>() { var model = GetCachedEdmModel(typeof(T)); var entities = model.FindDeclaredNavigationSource("Entities"); var parser = new ODataQueryOptionParser(model, entities.EntityType(), entities, Dictionary); var filter = Filter == null ? null : parser.ParseFilter(); var orderby = OrderBy == null ? null : parser.ParseOrderBy(); var search = Search == null ? null : parser.ParseSearch(); var apply = Apply == null ? null : parser.ParseApply(); var result = new QueryDescription <T>() { Skip = Skip == null ? 0 : parser.ParseSkip() ?? 0, Take = Top == null ? null : parser.ParseTop(), Filter = ParseFilter(filter), Sorting = ParseOrderBy(orderby), Search = ParseSearch(search), Grouping = ParseApply(apply) }; if (result.Take == null) { result.Page = result.Skip == 0 ? 1 : 2; } else { result.Page = (result.Skip / result.Take.Value) + 1; if (result.Skip % result.Take.Value > 0) { result.Page++; } } return(result); }
internal void AddAutoSelectExpandProperties() { bool containsAutoSelectExpandProperties = false; var autoExpandRawValue = GetAutoExpandRawValue(); var autoSelectRawValue = GetAutoSelectRawValue(); IDictionary <string, string> queryParameters = GetODataQueryParameters(); if (!String.IsNullOrEmpty(autoExpandRawValue) && !autoExpandRawValue.Equals(RawValues.Expand)) { queryParameters["$expand"] = autoExpandRawValue; containsAutoSelectExpandProperties = true; } else { autoExpandRawValue = RawValues.Expand; } if (!String.IsNullOrEmpty(autoSelectRawValue) && !autoSelectRawValue.Equals(RawValues.Select)) { queryParameters["$select"] = autoSelectRawValue; containsAutoSelectExpandProperties = true; } else { autoSelectRawValue = RawValues.Select; } if (containsAutoSelectExpandProperties) { _queryOptionParser = new ODataQueryOptionParser( Context.Model, Context.ElementType, Context.NavigationSource, queryParameters, Context.RequestContainer ); if (Apply != null) { _queryOptionParser.ParseApply(); } if (Compute != null) { _queryOptionParser.ParseCompute(); } var originalSelectExpand = SelectExpand; SelectExpand = new SelectExpandQueryOption( autoSelectRawValue, autoExpandRawValue, Context, _queryOptionParser); var typeLevelModelSettings = EdmLibHelpers.GetModelBoundQuerySettings(this.Context.ElementType, this.Context.Model, this.Context.DefaultQuerySettings); SelectExpand.SelectExpandClause.AllAutoSelected = (typeLevelModelSettings != null && typeLevelModelSettings.DefaultSelectType == SelectExpandType.Automatic); if (originalSelectExpand != null && originalSelectExpand.LevelsMaxLiteralExpansionDepth > 0) { SelectExpand.LevelsMaxLiteralExpansionDepth = originalSelectExpand.LevelsMaxLiteralExpansionDepth; } } }