public override Expression VisitSqlRoot(SqlRootExpression expression, object context)
        {
            if (expression.TableExpressions.Count == 0)
            {
                return(expression);
            }

            List <TableExpression> newTableExpressions = null;

            for (var i = 0; i < expression.TableExpressions.Count; i++)
            {
                TableExpression tableExpression = expression.TableExpressions[i];

                // process only normalized predicates. Ignore Sort as it has its own visitor.
                if (tableExpression.Kind != TableExpressionKind.Sort && tableExpression.NormalizedPredicate?.AcceptVisitor(Scout.Instance, context) == true)
                {
                    EnsureAllocatedAndPopulated(ref newTableExpressions, expression.TableExpressions, i);

                    // If this is the first expression, we need to add another expression before it
                    if (i == 0)
                    {
                        // seed with all resources so that we have something to restrict
                        newTableExpressions.Add(
                            new TableExpression(
                                tableExpression.SearchParameterQueryGenerator,
                                null,
                                tableExpression.DenormalizedPredicate,
                                TableExpressionKind.All));
                    }

                    newTableExpressions.Add((TableExpression)tableExpression.AcceptVisitor(this, context));
                }
                else
                {
                    newTableExpressions?.Add(tableExpression);
                }
            }

            if (newTableExpressions == null)
            {
                return(expression);
            }

            return(new SqlRootExpression(newTableExpressions, expression.DenormalizedExpressions));
        }
        public override Expression VisitSqlRoot(SqlRootExpression expression, object context)
        {
            if (expression.TableExpressions.Count == 0)
            {
                return(expression);
            }

            List <TableExpression> newTableExpressions = null;

            for (var i = 0; i < expression.TableExpressions.Count; i++)
            {
                TableExpression tableExpression = expression.TableExpressions[i];

                if (tableExpression.NormalizedPredicate.AcceptVisitor(Scout.Instance, null))
                {
                    EnsureAllocatedAndPopulated(ref newTableExpressions, expression.TableExpressions, i);

                    if (expression.TableExpressions.Count == 1)
                    {
                        // seed with all resources so that we have something to restrict
                        newTableExpressions.Add(
                            new TableExpression(
                                tableExpression.SearchParameterQueryGenerator,
                                null,
                                tableExpression.DenormalizedPredicate,
                                TableExpressionKind.All));
                    }

                    newTableExpressions.Add((TableExpression)tableExpression.AcceptVisitor(this, context));
                }
                else
                {
                    newTableExpressions?.Add(tableExpression);
                }
            }

            if (newTableExpressions == null)
            {
                return(expression);
            }

            return(new SqlRootExpression(newTableExpressions, expression.DenormalizedExpressions));
        }