/// <summary> /// Apply the filter query to the given IQueryable. /// </summary> /// <remarks> /// The <see cref="ODataQuerySettings.HandleNullPropagation"/> property specifies /// how this method should handle null propagation. /// </remarks> /// <param name="query">The original <see cref="IQueryable"/>.</param> /// <param name="querySettings">The <see cref="ODataQuerySettings"/> that contains all the query application related settings.</param> /// <returns>The new <see cref="IQueryable"/> after the filter query has been applied to.</returns> public IQueryable ApplyTo(IQueryable query, ODataQuerySettings querySettings) { if (query == null) { throw Error.ArgumentNull("query"); } if (querySettings == null) { throw Error.ArgumentNull("querySettings"); } if (Context.ElementClrType == null) { throw Error.NotSupported(SRResources.ApplyToOnUntypedQueryOption, "ApplyTo"); } FilterClause filterClause = FilterClause; Contract.Assert(filterClause != null); QueryBinderContext binderContext = new QueryBinderContext(Context.Model, querySettings, Context.ElementClrType); if (Compute != null) { binderContext.AddComputedProperties(Compute.ComputeClause.ComputedItems); } IFilterBinder binder = Context.GetFilterBinder(); return(binder.ApplyBind(query, filterClause, binderContext)); }
/// <summary> /// Translates an OData $filter represented by <see cref="FilterClause"/> to <see cref="Expression"/> and apply to <see cref="IQueryable" />. /// </summary> /// <param name="binder">The given filter binder.</param> /// <param name="query">The given queryable.</param> /// <param name="filterClause">The filter clause.</param> /// <param name="context">The query binder context.</param> /// <returns>The applied result.</returns> public static IQueryable ApplyBind(this IFilterBinder binder, IQueryable query, FilterClause filterClause, QueryBinderContext context) { if (binder == null) { throw Error.ArgumentNull(nameof(binder)); } if (query == null) { throw Error.ArgumentNull(nameof(query)); } if (filterClause == null) { throw Error.ArgumentNull(nameof(filterClause)); } if (context == null) { throw Error.ArgumentNull(nameof(context)); } Expression filterExp = binder.BindFilter(filterClause, context); return(ExpressionHelpers.Where(query, filterExp, context.ElementClrType)); }
/// <summary> /// Gets the <see cref="IFilterBinder"/>. /// </summary> /// <param name="context">The query context.</param> /// <returns>The built <see cref="IFilterBinder"/>.</returns> public static IFilterBinder GetFilterBinder(this ODataQueryContext context) { if (context == null) { throw Error.ArgumentNull(nameof(context)); } IFilterBinder binder = context.RequestContainer?.GetService <IFilterBinder>(); return(binder ?? new FilterBinder()); }
/// <summary> /// Translates an OData $filter represented by <see cref="FilterClause"/> to <see cref="Expression"/> and apply to <see cref="Expression" />. /// </summary> /// <param name="binder">The given filter binder.</param> /// <param name="source">The given source.</param> /// <param name="filterClause">The filter clause.</param> /// <param name="context">The query binder context.</param> /// <returns>The applied result.</returns> public static Expression ApplyBind(this IFilterBinder binder, Expression source, FilterClause filterClause, QueryBinderContext context) { if (binder == null) { throw Error.ArgumentNull(nameof(binder)); } if (source == null) { throw Error.ArgumentNull(nameof(source)); } if (filterClause == null) { throw Error.ArgumentNull(nameof(filterClause)); } if (context == null) { throw Error.ArgumentNull(nameof(context)); } Expression filterExp = binder.BindFilter(filterClause, context); Type elementType = context.ElementClrType; MethodInfo filterMethod; if (typeof(IQueryable).IsAssignableFrom(source.Type)) { filterMethod = ExpressionHelperMethods.QueryableWhereGeneric.MakeGenericMethod(elementType); } else { filterMethod = ExpressionHelperMethods.EnumerableWhereGeneric.MakeGenericMethod(elementType); } return(Expression.Call(filterMethod, source, filterExp)); }
/// <summary> /// Translates an OData $filter represented by <see cref="FilterClause"/> to <see cref="Expression"/> and apply to <see cref="IEnumerable" />. /// </summary> /// <param name="binder">The given filter binder.</param> /// <param name="query">The given IEnumerable.</param> /// <param name="filterClause">The filter clause.</param> /// <param name="context">The query binder context.</param> /// <returns>The applied result.</returns> public static IEnumerable ApplyBind(this IFilterBinder binder, IEnumerable query, FilterClause filterClause, QueryBinderContext context) { if (binder == null) { throw Error.ArgumentNull(nameof(binder)); } if (query == null) { throw Error.ArgumentNull(nameof(query)); } if (context == null) { throw Error.ArgumentNull(nameof(context)); } Expression filterExp = binder.BindFilter(filterClause, context); MethodInfo whereMethod = ExpressionHelperMethods.EnumerableWhereGeneric.MakeGenericMethod(context.ElementClrType); return(whereMethod.Invoke(null, new object[] { query, filterExp }) as IEnumerable); }
public DefaultScimUserManager(IUserAccountManager <UserAccount> userAccountManager, IFilterBinder filterBinder, IAttributeNameMapper mapper) { this.userAccountManager = userAccountManager; this.filterBinder = filterBinder; this.mapper = mapper; }
public DefaultScimUserManager(IUserAccountManager<UserAccount> userAccountManager, IFilterBinder filterBinder, IAttributeNameMapper mapper) { this.userAccountManager = userAccountManager; this.filterBinder = filterBinder; this.mapper = mapper; }
/// <summary> /// Apply the apply query to the given IQueryable. /// </summary> /// <remarks> /// The <see cref="ODataQuerySettings.HandleNullPropagation"/> property specifies /// how this method should handle null propagation. /// </remarks> /// <param name="query">The original <see cref="IQueryable"/>.</param> /// <param name="querySettings">The <see cref="ODataQuerySettings"/> that contains all the query application related settings.</param> /// <returns>The new <see cref="IQueryable"/> after the filter query has been applied to.</returns> public IQueryable ApplyTo(IQueryable query, ODataQuerySettings querySettings) { if (query == null) { throw Error.ArgumentNull(nameof(query)); } if (querySettings == null) { throw Error.ArgumentNull(nameof(querySettings)); } if (Context.ElementClrType == null) { throw Error.NotSupported(SRResources.ApplyToOnUntypedQueryOption, "ApplyTo"); } // Linq to SQL not supported for $apply if (query.Provider.GetType().Namespace == HandleNullPropagationOptionHelper.Linq2SqlQueryProviderNamespace) { throw Error.NotSupported(SRResources.ApplyQueryOptionNotSupportedForLinq2SQL); } ApplyClause applyClause = ApplyClause; Contract.Assert(applyClause != null); // The IWebApiAssembliesResolver service is internal and can only be injected by WebApi. // This code path may be used in cases when the service container is not available // and the service container is available but may not contain an instance of IWebApiAssembliesResolver. IAssemblyResolver assembliesResolver = AssemblyResolverHelper.Default; if (Context.RequestContainer != null) { IAssemblyResolver injectedResolver = Context.RequestContainer.GetService <IAssemblyResolver>(); if (injectedResolver != null) { assembliesResolver = injectedResolver; } } foreach (var transformation in applyClause.Transformations) { if (transformation.Kind == TransformationNodeKind.Aggregate || transformation.Kind == TransformationNodeKind.GroupBy) { var binder = new AggregationBinder(querySettings, assembliesResolver, ResultClrType, Context.Model, transformation); query = binder.Bind(query); this.ResultClrType = binder.ResultClrType; } else if (transformation.Kind == TransformationNodeKind.Compute) { var binder = new ComputeBinder(querySettings, assembliesResolver, ResultClrType, Context.Model, (ComputeTransformationNode)transformation); query = binder.Bind(query); this.ResultClrType = binder.ResultClrType; } else if (transformation.Kind == TransformationNodeKind.Filter) { var filterTransformation = transformation as FilterTransformationNode; IFilterBinder binder = Context.GetFilterBinder(); QueryBinderContext binderContext = new QueryBinderContext(Context.Model, querySettings, ResultClrType); query = binder.ApplyBind(query, filterTransformation.FilterClause, binderContext); } } return(query); }