/// <summary> /// 访问表达式中的函数调用 /// </summary> /// <param name="node"></param> /// <param name="fieldName"></param> /// <returns></returns> protected Expression VisitMethodCall(MethodCallExpression node, string fieldName) { string sqlMethodName = node.Method.Name.ToLower(); string callName = SqlMethodNameCallBack.MethodNameCallback(sqlMethodName); if (!string.IsNullOrEmpty(callName)) { parameters.Add(fieldName, new Parameter(callName, callName) { IsMethodType = true }); } else { throw new NotSupportedException(string.Format("{0}数据库中不支持函数{1}", "SqlServer", sqlMethodName)); } return(base.VisitMethodCall(node)); }
/// <summary> /// 访问方法 /// </summary> /// <param name="node"></param> /// <returns></returns> protected override Expression VisitMethodCall(MethodCallExpression node) { var methodInfo = node.Method; if (methodInfo.DeclaringType == typeof(SQLMethod)) { bool tleft = isleft; isleft = true; if (node.Arguments.Count > 0) { this.Visit(node.Arguments[0]); } isleft = tleft; switch (methodInfo.Name) { case "IsNull": sb.Append(" is NULL"); break; case "IsNotNull": sb.Append(" is NOT NULL"); break; default: string methodName = methodInfo.Name.ToLower(); string funcName = SqlMethodNameCallBack.MethodNameCallback(methodName); if (!string.IsNullOrEmpty(funcName)) { sb.Append(funcName); } else { throw new NotSupportedException( string.Format("{0}数据库中不支持函数{1}", "sqlserver", methodName)); } break; } } if (methodInfo.DeclaringType == typeof(string)) { switch (methodInfo.Name) { case "Contains": VisitStringFuncByOneParamter(node, v => string.Format("%{0}%", v)); break; case "StartsWith": VisitStringFuncByOneParamter(node, v => string.Format("{0}%", v)); break; case "EndsWith": VisitStringFuncByOneParamter(node, v => string.Format("%{0}", v)); break; } } if (methodInfo.DeclaringType == typeof(Enumerable)) { if (methodInfo.DeclaringType == typeof(Enumerable)) { this.Visit(node.Arguments[1]); sb.Append(" In "); this.Visit(node.Arguments[0]); } } #if COREFX if (methodInfo.DeclaringType.GetTypeInfo().GetInterface("IEnumerable", false) != null) #else if (methodInfo.DeclaringType?.GetInterface("IEnumerable", false) != null) #endif { this.Visit(node.Arguments[0]); sb.Append(" In "); this.Visit(node.Object); } if (methodInfo.DeclaringType == typeof(System.Convert)) { this.Visit(node.Arguments[0]); } return(node); }