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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); }
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 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); }
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); }
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); }
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); }
private List <string> GetSubItems() { var isSubSubQuery = this.allMethods.Select(it => it.ToString()).Any(it => Regex.Matches(it, "Subquery").Count > 1); var isubList = this.allMethods.Select(exp => { if (isSubSubQuery) { this.context.JoinIndex = 1; this.context.SubQueryIndex = 0; } 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(); var isJoin = isubList.Any(it => it is SubInnerJoin || it is SubLeftJoin); if (isJoin) { this.context.JoinIndex++; } List <string> result = isubList.Select(it => { it.HasWhere = isHasWhere; return(it.GetValue(it.Expression)); }).ToList(); this.context.JoinIndex = 0; return(result); }
public string GetValue(Expression expression = null) { var exp = expression as MethodCallExpression; return("MAX(" + SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldSingle) + ")"); }