internal static List <SelectExpression> Gather(Expression source) { RedundantSubqueryGatherer gatherer = new RedundantSubqueryGatherer(); gatherer.Visit(source); return(gatherer.redundant); }
protected override Expression VisitProjection(ProjectionExpression proj) { proj = (ProjectionExpression)base.VisitProjection(proj); if (proj.Select.From is SelectExpression) { List <SelectExpression> redundant = RedundantSubqueryGatherer.Gather(proj.Select); if (redundant != null) { proj = SubqueryRemover.Remove(proj, redundant); } } return(proj); }
protected override Expression VisitSelect(SelectExpression select) { select = (SelectExpression)base.VisitSelect(select); // first remove all purely redundant subqueries List <SelectExpression> redundant = RedundantSubqueryGatherer.Gather(select.From); if (redundant != null) { select = SubqueryRemover.Remove(select, redundant); } return(select); }