internal void QWhere <TSource>(Expression <Func <TSource, bool> > predicate) { LambdaExpression fixedPredicate = predicate; if (GroupByKeySelector != null) { throw new NotSupportedException("Pomona LINQ provider does not support calling Where() after GroupBy()"); } if (SelectExpression != null) { fixedPredicate = MergeWhereAfterSelect(fixedPredicate); } this.whereExpressions.Add(fixedPredicate); if (WherePredicate == null) { WherePredicate = fixedPredicate; } else { var replacer = new LamdbaParameterReplacer(fixedPredicate.Parameters[0], WherePredicate.Parameters[0]); var rewrittenPredicateBody = replacer.Visit(fixedPredicate.Body); WherePredicate = Expression.Lambda( WherePredicate.Type, Expression.AndAlso(WherePredicate.Body, rewrittenPredicateBody), WherePredicate.Parameters); } }
private LambdaExpression MergeWhereAfterSelect(LambdaExpression predicate) { var parameter = Expression.Parameter(SelectExpression.Parameters[0].Type, SelectExpression.Parameters[0].Name); var fixedSelectExpr = LamdbaParameterReplacer.Replace(SelectExpression.Body, SelectExpression.Parameters[0], parameter); var expandedBody = LamdbaParameterReplacer.Replace(predicate.Body, predicate.Parameters[0], fixedSelectExpr); var newBody = new CollapseDisplayObjectsVisitor().Visit(expandedBody); return(Expression.Lambda(newBody, parameter)); }
internal void QOfType <TResult>() { if (!ElementType.IsAssignableFrom(typeof(TResult))) { throw new NotSupportedException("Only supports OfType'ing to inherited type."); } if (SelectExpression != null) { throw new NotSupportedException("Does only support OfType at start of query."); } if (WherePredicate != null) { var newParam = Expression.Parameter(typeof(TResult), WherePredicate.Parameters[0].Name); var replacer = new LamdbaParameterReplacer(WherePredicate.Parameters[0], newParam); WherePredicate = Expression.Lambda(replacer.Visit(WherePredicate.Body), newParam); } ElementType = typeof(TResult); }