Beispiel #1
0
        public string GetValue(Expression expression)
        {
            var    exp   = expression as MethodCallExpression;
            object value = null;

            try
            {
                value = ExpressionTool.DynamicInvoke(exp.Arguments[0]);
            }
            catch
            {
                Check.Exception(true, ErrorMessage.WhereIFCheck, exp.Arguments[0].ToString());
            }
            var isWhere = Convert.ToBoolean(value);

            if (!Convert.ToBoolean(isWhere))
            {
                return("WHERE 1=1 ");
            }
            var argExp            = exp.Arguments[1];
            var result            = "WHERE " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);;
            var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;

            result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            return(result);
        }
Beispiel #2
0
        public string GetValue(Expression expression)
        {
            var exp               = expression as MethodCallExpression;
            var argExp            = exp.Arguments[0];
            var result            = "ORDER BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle) + " DESC";
            var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;

            result = result.Replace(selfParameterName, string.Empty);
            return(result);
        }
Beispiel #3
0
        public string GetValue(Expression expression = null)
        {
            var exp        = expression as MethodCallExpression;
            var entityType = (exp.Arguments[0] as LambdaExpression).Parameters[0].Type;

            if (this.Context.InitMappingInfo != null)
            {
                this.Context.InitMappingInfo(entityType);
                this.Context.RefreshMapping();
            }
            return(SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle));
        }
Beispiel #4
0
        public string GetValue(Expression expression)
        {
            if (this.Context is OracleExpressionContext)
            {
                throw new Exception("Oracle Subquery can't OrderBy");
            }
            var exp               = expression as MethodCallExpression;
            var argExp            = exp.Arguments[0];
            var result            = "ORDER BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle);
            var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;

            result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            return(result);
        }
        public string GetSql()
        {
            allMethods.Reverse();
            List <KeyValuePair <string, string> > sqls = new List <KeyValuePair <string, string> >();

            foreach (var methodExp in allMethods)
            {
                var isFirst = allMethods.First() == methodExp;
                var isLast  = allMethods.Last() == methodExp;
                var sql     = SubTools.GetMethodValue(this.context, methodExp.Arguments[0], this.context.IsSingle?ResolveExpressType.WhereSingle:ResolveExpressType.WhereMultiple);
                sqls.Add(new KeyValuePair <string, string>(methodExp.Method.Name, sql));
            }
            var result = this.context.DbMehtods.CaseWhen(sqls);

            return(result);
        }
Beispiel #6
0
        public string GetValue(Expression expression = null)
        {
            var exp        = expression as MethodCallExpression;
            var argExp     = exp.Arguments[0];
            var parametres = (argExp as LambdaExpression).Parameters;

            if ((argExp as LambdaExpression).Body is UnaryExpression)
            {
                argExp = ((argExp as LambdaExpression).Body as UnaryExpression).Operand;
            }
            var result            = "MAX(" + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple) + ")";
            var selfParameterName = Context.GetTranslationColumnName(parametres.First().Name) + UtilConstants.Dot;

            result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            return(result);
        }
Beispiel #7
0
        public string GetValue(Expression expression)
        {
            var exp    = expression as MethodCallExpression;
            var argExp = exp.Arguments[0];
            var type   = ResolveExpressType.FieldSingle;

            if ((argExp as LambdaExpression).Body is NewExpression)
            {
                type = ResolveExpressType.ArraySingle;
            }
            var result = "GROUP BY " + SubTools.GetMethodValue(this.Context, argExp, type);

            result = result.TrimEnd(',');
            var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;

            result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            return(result);
        }
Beispiel #8
0
        public string GetValue(Expression expression)
        {
            var exp    = expression as MethodCallExpression;
            var argExp = exp.Arguments[0];
            var result = "WHERE " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);


            var regex = @"^WHERE  (\@Const\d+) $";

            if (this.Context is OracleExpressionContext)
            {
                regex = @"^WHERE  (\:Const\d+) $";
            }
            if (Regex.IsMatch(result, regex))
            {
                result = "WHERE " + this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value).Value;
                return(result);
            }

            var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;

            result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            return(result);
        }
Beispiel #9
0
        public string GetValue(Expression expression = null)
        {
            var exp = expression as MethodCallExpression;

            return("AVG(" + SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle) + ")");
        }