Beispiel #1
0
        private void GetConfigValue(MethodCallExpression express, ExpressionParameter parameter)
        {
            var    exp  = express.Arguments[0];
            var    name = Regex.Match(express.Method.ToString(), @"GetConfigValue\[(.+)\]").Groups[1].Value;
            string code = null;

            if (express.Arguments.Count > 1)
            {
                code = ExpressionTool.GetExpressionValue(express.Arguments[1]) + "";
            }
            var entity = SqlFuncExtendsion.TableInfos.FirstOrDefault(y => y.Type.Name == name && y.Code == code);

            Check.Exception(entity == null, string.Format("GetConfigValue no configuration  Entity={0} UniqueCode={1}", name, code));
            string sql = " (SELECT {0} FROM {1} WHERE {2}={3}";

            if (ExpressionTool.IsUnConvertExpress(exp))
            {
                exp = (exp as UnaryExpression).Operand;
            }
            var member      = exp as MemberExpression;
            var it          = member.Expression;
            var type        = it.Type;
            var properyName = member.Member.Name;
            var eqName      = string.Format("{0}.{1}", this.Context.GetTranslationColumnName(it.ToString()), this.Context.GetDbColumnName(type.Name, properyName));

            if (this.Context.IsSingle)
            {
                this.Context.SingleTableNameSubqueryShortName = it.ToString();
            }
            sql = string.Format(sql, entity.Value, this.Context.GetTranslationColumnName(entity.TableName), entity.Key, eqName);
            if (entity.Parameter != null)
            {
                foreach (var item in entity.Parameter)
                {
                    var oldName = item.ParameterName;
                    item.ParameterName = oldName + "_con_" + this.Context.ParameterIndex;
                    entity.Where       = entity.Where.Replace(oldName, item.ParameterName);
                }
                this.Context.ParameterIndex++;
                this.Context.Parameters.AddRange(entity.Parameter);
            }
            if (entity.Where.HasValue())
            {
                sql += " AND " + entity.Where;
            }
            sql += " )";
            if (this.Context.ResolveType.IsIn(ResolveExpressType.SelectMultiple, ResolveExpressType.SelectSingle, ResolveExpressType.Update))
            {
                parameter.BaseParameter.CommonTempData = sql;
            }
            else
            {
                AppendMember(parameter, parameter.IsLeft, sql);
            }
        }
Beispiel #2
0
        private void GetConfigValue(MethodCallExpression express, ExpressionParameter parameter)
        {
            var    exp  = express.Arguments[0];
            var    name = Regex.Match(express.Method.ToString(), @"GetConfigValue\[(.+)\]").Groups[1].Value;
            string code = null;

            if (express.Arguments.Count > 1)
            {
                code = ExpressionTool.GetExpressionValue(express.Arguments[1]) + "";
            }
            var entityDb = SqlFuncExtendsion.TableInfos.FirstOrDefault(y => y.Type.Name == name && y.Code == code);

            Check.Exception(entityDb == null, string.Format("GetConfigValue no configuration  Entity={0} UniqueCode={1}", name, code));
            var entity = new ConfigTableInfo()
            {
                Code      = entityDb.Code,
                TableName = entityDb.TableName,
                Key       = entityDb.Key,
                Parameter = new List <SugarParameter>(),
                Type      = entityDb.Type,
                Value     = entityDb.Value,
                Where     = entityDb.Where
            };

            if (entityDb.Parameter != null && entityDb.Parameter.Any())
            {
                foreach (var item in entityDb.Parameter)
                {
                    entity.Parameter.Add(new SugarParameter("", null)
                    {
                        DbType                  = item.DbType,
                        Direction               = item.Direction,
                        IsArray                 = item.IsArray,
                        IsJson                  = item.IsJson,
                        IsNullable              = item.IsNullable,
                        IsRefCursor             = item.IsRefCursor,
                        ParameterName           = item.ParameterName,
                        Size                    = item.Size,
                        SourceColumn            = item.SourceColumn,
                        SourceColumnNullMapping = item.SourceColumnNullMapping,
                        SourceVersion           = item.SourceVersion,
                        TempDate                = item.TempDate,
                        TypeName                = item.TypeName,
                        Value                   = item.Value,
                        _Size                   = item._Size
                    });
                }
            }
            string sql = " (SELECT {0} FROM {1} WHERE {2}={3}";

            if (ExpressionTool.IsUnConvertExpress(exp))
            {
                exp = (exp as UnaryExpression).Operand;
            }
            var member      = exp as MemberExpression;
            var it          = member.Expression;
            var type        = it.Type;
            var properyName = member.Member.Name;
            var eqName      = string.Format("{0}.{1}", this.Context.GetTranslationColumnName(it.ToString()), this.Context.GetDbColumnName(type.Name, properyName));

            if (this.Context.IsSingle)
            {
                this.Context.SingleTableNameSubqueryShortName = it.ToString();
            }
            sql = string.Format(sql, entity.Value, this.Context.GetTranslationColumnName(entity.TableName), entity.Key, eqName);
            if (entity.Parameter != null)
            {
                foreach (var item in entity.Parameter)
                {
                    var oldName = item.ParameterName;
                    item.ParameterName = Regex.Split(oldName, "_con_").First() + "_con_" + this.Context.ParameterIndex;
                    entity.Where       = entity.Where.Replace(oldName, item.ParameterName);
                }
                this.Context.ParameterIndex++;
                this.Context.Parameters.AddRange(entity.Parameter);
            }
            if (entity.Where.HasValue())
            {
                sql += " AND " + entity.Where;
            }
            sql += " )";
            if (this.Context.ResolveType.IsIn(ResolveExpressType.SelectMultiple, ResolveExpressType.SelectSingle, ResolveExpressType.Update))
            {
                parameter.BaseParameter.CommonTempData = sql;
            }
            else
            {
                AppendMember(parameter, parameter.IsLeft, sql);
            }
        }