protected virtual DbLambda VisitLambda(DbLambda lambda)
        {
            Check.NotNull(lambda, "lambda");

            var result     = lambda;
            var newFormals = VisitList(
                lambda.Variables, varRef =>
            {
                var newVarType = VisitTypeUsage(varRef.ResultType);
                if (!ReferenceEquals(varRef.ResultType, newVarType))
                {
                    return(CqtBuilder.Variable(newVarType, varRef.VariableName));
                }
                else
                {
                    return(varRef);
                }
            }
                );

            EnterScope(newFormals.ToArray()); // ToArray: Don't pass the List instance directly to OnEnterScope
            var newBody = VisitExpression(lambda.Body);

            ExitScope();

            if (!ReferenceEquals(lambda.Variables, newFormals)
                ||
                !ReferenceEquals(lambda.Body, newBody))
            {
                result = CqtBuilder.Lambda(newBody, newFormals);
            }
            return(result);
        }