public override Expression ApplyPolicy(Expression expression, MemberInfo member) { if (this.policy.operations.TryGetValue(member, out List <LambdaExpression> ops)) { var result = expression; foreach (var fnOp in ops) { var pop = ExpressionEvaluator.Eval(fnOp, this.Translator.Mapper.Mapping.CanBeEvaluatedLocally); result = this.Translator.Mapper.ApplyMapping(Expression.Invoke(pop, result)); } var projection = result as DbProjectionExpression; if (projection.Type != expression.Type) { var fnAgg = DbAggregator.GetAggregator(expression.Type, projection.Type); projection = new DbProjectionExpression(projection.Select, projection.Projector, fnAgg); } return(projection); } return(expression); }
protected override Expression VisitProjection(DbProjectionExpression proj) { // treat these like scalar subqueries if (proj.Projector is DbColumnExpression) { this.Write("("); this.WriteLine(Indentation.Inner); this.Visit(proj.Select); this.Write(")"); this.Indent(Indentation.Outer); } else { throw new NotSupportedException("Non-scalar projections cannot be translated to SQL."); } return(proj); }