Expression IQueryPolicy.ApplyPolicy(Expression expression, MemberInfo member) { List <LambdaExpression> ops; if (operations.TryGetValue(member, out ops)) { var syntax = Database.Provider.GetService <ISyntaxProvider>(); var result = expression; foreach (var fnOp in ops) { var pop = PartialEvaluator.Eval(fnOp); result = QueryBinder.Bind(Expression.Invoke(pop, result), syntax); } var projection = (ProjectionExpression)result; if (projection.Type != expression.Type) { var fnAgg = QueryUtility.GetAggregator(expression.Type, projection.Type); projection = new ProjectionExpression(projection.Select, projection.Projector, fnAgg); } return(projection); } return(expression); }
public Expression ApplyPolicy(Expression expression, MemberInfo member, Func <Expression, Expression> builder) { if (_operations.TryGetValue(member, out List <LambdaExpression> ops)) { var syntax = _provider.GetService <ISyntaxProvider>(); var result = expression; foreach (var fnOp in ops) { var pop = PartialEvaluator.Eval(fnOp); result = builder(Expression.Invoke(pop, result)); } var projection = (ProjectionExpression)result; if (projection.Type != expression.Type) { var fnAgg = QueryUtility.GetAggregator(expression.Type, projection.Type); projection = new ProjectionExpression(projection.Select, projection.Projector, fnAgg, projection.IsAsync, projection.IsNoTracking); } return(projection); } return(expression); }