protected virtual DbLambda VisitLambda(DbLambda lambda) { EntityUtil.CheckArgumentNull(lambda, "lambda"); DbLambda result = lambda; IList <DbVariableReferenceExpression> newFormals = this.VisitList(lambda.Variables, varRef => { TypeUsage newVarType = this.VisitTypeUsage(varRef.ResultType); if (!object.ReferenceEquals(varRef.ResultType, newVarType)) { return(CqtBuilder.Variable(newVarType, varRef.VariableName)); } else { return(varRef); } } ); this.EnterScope(newFormals.ToArray()); // ToArray: Don't pass the List instance directly to OnEnterScope DbExpression newBody = this.VisitExpression(lambda.Body); this.ExitScope(); if (!object.ReferenceEquals(lambda.Variables, newFormals) || !object.ReferenceEquals(lambda.Body, newBody)) { result = CqtBuilder.Lambda(newBody, newFormals); } return(result); }