Ejemplo n.º 1
0
 public override string ToString()
 {
     if (Value is Array) {
         var arg = (Array)Value;
         var list = new List<string>(arg.Length);
         foreach (var item in arg) {
             var sql = new SqlWhereConstant { Value = item };
             list.Add(sql.ToString());
         }
         return string.Format("({0})", string.Join(",", list.ToArray()));
     }
     return Configuration.DatabaseProvider.GetDBValue(Value);
 }
Ejemplo n.º 2
0
        private static SqlExpression VisitMethodCall(MethodCallExpression methodCallExpression)
        {
            if (methodCallExpression.Method.DeclaringType.Name == "String") {
                return new SqlWhereClause { Left = Visit(methodCallExpression.Object), Operator = SqlOperator.Like, Right = VisitLike(Visit(methodCallExpression.Arguments[0]), methodCallExpression) };
            }

            if (methodCallExpression.Method.Name == "Contains") {
                var arg = ((SqlWhereConstant)Visit(methodCallExpression.Arguments[0])).Value;
                var column = (MemberExpression)methodCallExpression.Arguments[1];
                var left = new SqlWhereColumn { Prefix = ((ParameterExpression)column.Expression).Name, Name = QueryTranslator.GetColumnName(column.Member) };
                var right = new SqlWhereConstant { Value = arg };
                var opera = SqlOperator.In;

                return new SqlWhereClause { Left = left, Operator = opera, Right = right };
            }

            if (Type.GetTypeCode(methodCallExpression.Method.ReturnType) != TypeCode.Object) {
                var objExpression = Visit(methodCallExpression.Object);
                if (objExpression is SqlWhereConstant) {
                    var args = GetArgumentsValue(methodCallExpression.Arguments);
                    return new SqlWhereConstant { Value = methodCallExpression.Method.Invoke(((SqlWhereConstant)objExpression).Value, args) };
                }
            }

            return null;
        }