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;
                if (methodExp.Arguments.Count == 0)
                {
                    sqls.Add(new KeyValuePair <string, string>(methodExp.Method.Name, "null"));
                }
                else
                {
                    var sql = SubTools.GetMethodValue(this.context, methodExp.Arguments[0], this.context.IsSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple);
                    if (methodExp.Method.Name == "IF")
                    {
                        var parameter = this.context.Parameters.FirstOrDefault(it => it.ParameterName == sql.Trim());
                        if (parameter != null && parameter.Value is bool)
                        {
                            sql = Convert.ToBoolean(parameter.Value) ? " 1=1 " : " 1=2 ";
                            this.context.Parameters.Remove(parameter);
                        }
                    }
                    sqls.Add(new KeyValuePair <string, string>(methodExp.Method.Name, sql));
                }
            }
            var result = this.context.DbMehtods.CaseWhen(sqls);

            return(result);
        }
Exemple #2
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("");
            }
            var argExp            = exp.Arguments[1];
            var result            = "AND " + 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);
        }
Exemple #3
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 argLambda = argExp as LambdaExpression;

            if (this.Context.InitMappingInfo != null && argLambda != null && argLambda.Parameters.Count > 0)
            {
                foreach (var item in argLambda.Parameters)
                {
                    this.Context.InitMappingInfo(item.Type);
                }
                this.Context.RefreshMapping();
            }
            var result            = "MIN(" + 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);
        }
Exemple #4
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();
            }
            var result = "";

            if (this.Context.JoinIndex == 0)
            {
                result = SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle);
            }
            else
            {
                result = SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldMultiple);
            }

            SetShortName(exp, result);

            return(result);
        }
Exemple #5
0
        public string GetValue(Expression expression)
        {
            var exp    = expression as MethodCallExpression;
            var argExp = exp.Arguments[0];
            var result = "AND " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.WhereMultiple);


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

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

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

            if (this.Context.JoinIndex == 0)
            {
                result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            }
            return(result);
        }
Exemple #6
0
        public string GetValue(Expression expression = null)
        {
            var exp       = expression as MethodCallExpression;
            var expString = SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.WhereSingle)?.Trim();
            var result    = this.Context.Parameters.First(it => it.ParameterName == expString).Value + "";

            return("$SubAs:" + result);
        }
Exemple #7
0
        public string GetValue(Expression expression)
        {
            var exp               = expression as MethodCallExpression;
            var argExp            = exp.Arguments[0];
            var result            = "GROUP 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, string.Empty);
            return(result);
        }
        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 selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;

            result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            return(result);
        }
Exemple #9
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));
        }
Exemple #10
0
        public string GetValue(Expression expression)
        {
            var exp = expression as MethodCallExpression;

            if (Regex.Matches(expression.ToString(), "Subqueryable").Count >= 2)
            {
                new SubSelect()
                {
                    Context = this.Context
                }.SetShortName(exp, "+");
            }
            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 (this.Context is DmExpressionContext)
            {
                regex = @"^WHERE  (\:Const\d+) $";
            }
            if (Regex.IsMatch(result, regex))
            {
                var value = GetValue(result, regex);
                if (value is Expression)
                {
                    var p = this.Context.Parameters.First(it => it.ParameterName == Regex.Match(result, regex).Groups[1].Value);
                    result = "WHERE " + SubTools.GetMethodValue(Context, value as Expression, ResolveExpressType.WhereMultiple);
                    argExp = value as Expression;
                    this.Context.Parameters.Remove(p);
                }
                else
                {
                    result = "WHERE " + value;
                    return(result);
                }
            }

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

            if (this.Context.JoinIndex == 0)
            {
                result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            }
            return(result);
        }
Exemple #11
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);
        }
Exemple #12
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            = "SUM(" + 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);
        }
        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);
        }
Exemple #14
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);
        }
Exemple #15
0
        public string GetValue(Expression expression)
        {
            var exp       = expression as MethodCallExpression;
            var argExp    = exp.Arguments[0];
            var name      = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters[0].Name);
            var parameter = (argExp as LambdaExpression).Parameters[1];

            Context.InitMappingInfo(parameter.Type);
            var tableName  = Context.GetTranslationTableName(parameter.Type.Name, true);
            var joinString = string.Format(" {2} LEFT JOIN {1} {0} ",
                                           this.Context.GetTranslationColumnName(parameter.Name),
                                           tableName,
                                           this.Context.JoinIndex == 1?name:"");
            var result = joinString + "ON " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);

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

            //result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            return(result);
        }
Exemple #16
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());
            }
            if (Regex.Matches(expression.ToString(), "Subqueryable").Count >= 2)
            {
                new SubSelect()
                {
                    Context = this.Context
                }.SetShortNameNext(exp, "+");
            }
            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;

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

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