コード例 #1
0
ファイル: SubWhereIF.cs プロジェクト: mahonecode/Agile.Data
        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);
        }
コード例 #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);
        }
コード例 #3
0
ファイル: SubResolve.cs プロジェクト: mahonecode/Agile.Data
        private List <string> GetSubItems()
        {
            var isubList = this.allMethods.Select(exp =>
            {
                var methodName = exp.Method.Name;
                var items      = SubTools.SubItems(this.context);
                var item       = items.First(s => s.Name == methodName);
                if (item is SubWhere && hasWhere == false)
                {
                    hasWhere = true;
                }
                else if (item is SubWhere)
                {
                    item = items.First(s => s is SubAnd);
                }

                if (item is SubWhereIF && hasWhere == false)
                {
                    hasWhere = true;
                }
                else if (item is SubWhereIF)
                {
                    item = items.First(s => s is SubAndIF);
                }

                item.Context    = this.context;
                item.Expression = exp;
                return(item);
            }).ToList();

            isubList.Insert(0, new SubBegin());
            if (isubList.Any(it => it is SubSelect))
            {
                isubList.Add(new SubTop()
                {
                    Context = this.context
                });
            }
            if (isubList.Any(it => it is SubAny || it is SubNotAny))
            {
                isubList.Add(new SubLeftBracket());
                isubList.Add(new SubRightBracket());
                isubList.Add(new SubSelectDefault());
            }
            isubList = isubList.OrderBy(it => it.Sort).ToList();
            var           isHasWhere = isubList.Where(it => it is SubWhere).Any();
            List <string> result     = isubList.Select(it =>
            {
                it.HasWhere = isHasWhere;
                return(it.GetValue(it.Expression));
            }).ToList();

            return(result);
        }
コード例 #4
0
ファイル: SubSelect.cs プロジェクト: mahonecode/Agile.Data
        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));
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: SubSum.cs プロジェクト: mahonecode/Agile.Data
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: SubGroupBy.cs プロジェクト: mahonecode/Agile.Data
        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);
        }
コード例 #9
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 (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;

            result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
            return(result);
        }
コード例 #10
0
ファイル: SubAvg.cs プロジェクト: mahonecode/Agile.Data
        public string GetValue(Expression expression = null)
        {
            var exp = expression as MethodCallExpression;

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