コード例 #1
0
ファイル: BaseResolve.cs プロジェクト: zhaiqf0126/SqlSugar
        public BaseResolve Start()
        {
            Context.Index++;
            Expression          expression = this.Expression;
            ExpressionParameter parameter  = new ExpressionParameter()
            {
                Context           = this.Context,
                CurrentExpression = expression,
                IsLeft            = this.IsLeft,
                BaseExpression    = this.ExactExpression,
                BaseParameter     = this.BaseParameter,
                Index             = Context.Index
            };

            if (expression is LambdaExpression)
            {
                return(new LambdaExpressionResolve(parameter));
            }
            else if (expression is BinaryExpression && expression.NodeType == ExpressionType.Coalesce)
            {
                return(new CoalesceResolveItems(parameter));
            }
            else if (expression is BinaryExpression)
            {
                return(new BinaryExpressionResolve(parameter));
            }
            else if (expression is BlockExpression)
            {
                Check.ThrowNotSupportedException("BlockExpression");
            }
            else if (expression is ConditionalExpression)
            {
                return(new ConditionalExpressionResolve(parameter));
            }
            else if (expression is MethodCallExpression)
            {
                return(new MethodCallExpressionResolve(parameter));
            }
            else if (expression is MemberExpression && ((MemberExpression)expression).Expression == null)
            {
                return(new MemberNoExpressionResolve(parameter));
            }
            else if (expression is MemberExpression && ((MemberExpression)expression).Expression.NodeType == ExpressionType.Constant)
            {
                return(new MemberConstExpressionResolve(parameter));
            }
            else if (expression is MemberExpression && ((MemberExpression)expression).Expression.NodeType == ExpressionType.New)
            {
                return(new MemberNewExpressionResolve(parameter));
            }
            else if (expression is ConstantExpression)
            {
                return(new ConstantExpressionResolve(parameter));
            }
            else if (expression is MemberExpression)
            {
                return(new MemberExpressionResolve(parameter));
            }
            else if (expression is UnaryExpression)
            {
                return(new UnaryExpressionResolve(parameter));
            }
            else if (expression is MemberInitExpression)
            {
                return(new MemberInitExpressionResolve(parameter));
            }
            else if (expression is NewExpression)
            {
                return(new NewExpressionResolve(parameter));
            }
            else if (expression is NewArrayExpression)
            {
                return(new NewArrayExpessionResolve(parameter));
            }
            else if (expression is ParameterExpression)
            {
                return(new TypeParameterExpressionReolve(parameter));
            }
            else if (expression != null && expression.NodeType.IsIn(ExpressionType.NewArrayBounds))
            {
                Check.ThrowNotSupportedException("ExpressionType.NewArrayBounds");
            }
            return(null);
        }
コード例 #2
0
 public override bool BackupDataBase(string databaseName, string fullFileName)
 {
     Check.ThrowNotSupportedException("PgSql BackupDataBase NotSupported");
     return(false);
 }
コード例 #3
0
ファイル: BaseResolve.cs プロジェクト: zhaiqf0126/SqlSugar
 protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName)
 {
     if (item is ConstantExpression)
     {
         this.Expression = item;
         this.Start();
         string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
         this.Context.ParameterIndex++;
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
         this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
     }
     else if ((item is MemberExpression) && ((MemberExpression)item).Expression == null)
     {
         var    paramterValue = ExpressionTool.GetPropertyValue(item as MemberExpression);
         string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
         this.Context.ParameterIndex++;
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
         this.Context.Parameters.Add(new SugarParameter(parameterName, paramterValue));
     }
     else if ((item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
     {
         this.Expression = item;
         this.Start();
         string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
         this.Context.ParameterIndex++;
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
         this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
     }
     else if (item is MemberExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             this.Context.Result.CurrentParameter       = parameter;
             this.Context.Result.IsLockCurrentParameter = true;
             parameter.IsAppendTempDate();
             this.Expression = item;
             if (IsBoolValue(item))
             {
                 this.Expression = (item as MemberExpression).Expression;
             }
             this.Start();
             parameter.IsAppendResult();
             this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
             this.Context.Result.CurrentParameter = null;
         }
     }
     else if (item is UnaryExpression && ((UnaryExpression)item).Operand is MemberExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             var expression    = ((UnaryExpression)item).Operand as MemberExpression;
             var isDateTimeNow = ((UnaryExpression)item).Operand.ToString() == "DateTime.Now";
             if (expression.Expression == null && !isDateTimeNow)
             {
                 this.Context.Result.CurrentParameter       = parameter;
                 this.Context.Result.IsLockCurrentParameter = true;
                 parameter.IsAppendTempDate();
                 this.Expression = item;
                 this.Start();
                 parameter.IsAppendResult();
                 this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
                 this.Context.Result.CurrentParameter = null;
             }
             else if (expression.Expression is ConstantExpression || isDateTimeNow)
             {
                 string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
                 this.Context.ParameterIndex++;
                 parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
                 this.Context.Parameters.Add(new SugarParameter(parameterName, ExpressionTool.GetMemberValue(expression.Member, expression)));
             }
             else
             {
                 this.Context.Result.CurrentParameter       = parameter;
                 this.Context.Result.IsLockCurrentParameter = true;
                 parameter.IsAppendTempDate();
                 this.Expression = expression;
                 this.Start();
                 parameter.IsAppendResult();
                 this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
                 this.Context.Result.CurrentParameter = null;
             }
         }
     }
     else if (item is UnaryExpression && ((UnaryExpression)item).Operand is ConstantExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             this.Expression = ((UnaryExpression)item).Operand;
             this.Start();
             string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
             this.Context.ParameterIndex++;
             parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
             this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
         }
     }
     else if (item is BinaryExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             var newContext         = this.Context.GetCopyContextWithMapping();
             var resolveExpressType = this.Context.IsSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple;
             newContext.Resolve(item, resolveExpressType);
             this.Context.Index          = newContext.Index;
             this.Context.ParameterIndex = newContext.ParameterIndex;
             if (newContext.Parameters.HasValue())
             {
                 this.Context.Parameters.AddRange(newContext.Parameters);
             }
             this.Context.Result.Append(this.Context.GetAsString(asName, newContext.Result.GetString()));
             this.Context.Result.CurrentParameter = null;
             if (this.Context.SingleTableNameSubqueryShortName.IsNullOrEmpty() && newContext.SingleTableNameSubqueryShortName.HasValue())
             {
                 this.Context.SingleTableNameSubqueryShortName = newContext.SingleTableNameSubqueryShortName;
             }
         }
     }
     else if (item.Type.IsClass())
     {
         this.Expression = item;
         this.Start();
         var shortName      = parameter.CommonTempData;
         var listProperties = item.Type.GetProperties().Cast <PropertyInfo>().ToList();
         foreach (var property in listProperties)
         {
             var hasIgnore = this.Context.IgnoreComumnList != null && this.Context.IgnoreComumnList.Any(it => it.EntityName.Equals(item.Type.Name, StringComparison.CurrentCultureIgnoreCase) && it.PropertyName.Equals(property.Name, StringComparison.CurrentCultureIgnoreCase));
             if (hasIgnore)
             {
                 continue;
             }
             if (property.PropertyType.IsClass())
             {
                 var comumnInfo = property.GetCustomAttribute <SugarColumn>();
                 if (comumnInfo != null && comumnInfo.IsJson)
                 {
                     asName = GetAsName(item, shortName, property);
                 }
             }
             else
             {
                 asName = GetAsName(item, shortName, property);
             }
         }
     }
     else if (item.Type == UtilConstants.BoolType && item is MethodCallExpression && (item as MethodCallExpression).Method.Name == "Any" && IsSubMethod(item as MethodCallExpression))
     {
         this.Expression = item;
         this.Start();
         var sql = this.Context.DbMehtods.IIF(new MethodCallExpressionModel()
         {
             Args = new List <MethodCallExpressionArgs>()
             {
                 new MethodCallExpressionArgs()
                 {
                     IsMember   = true,
                     MemberName = parameter.CommonTempData.ObjToString()
                 },
                 new MethodCallExpressionArgs()
                 {
                     IsMember   = true,
                     MemberName = 1
                 },
                 new MethodCallExpressionArgs()
                 {
                     IsMember   = true,
                     MemberName = 0
                 }
             }
         });
         parameter.Context.Result.Append(this.Context.GetAsString(asName, sql));
     }
     else if (item is MethodCallExpression || item is UnaryExpression || item is ConditionalExpression || item.NodeType == ExpressionType.Coalesce)
     {
         this.Expression = item;
         this.Start();
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
     }
     else
     {
         Check.ThrowNotSupportedException(item.GetType().Name);
     }
 }
コード例 #4
0
ファイル: BaseResolve.cs プロジェクト: zdl8061/sqlsugar
 protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName)
 {
     if (item is ConstantExpression)
     {
         this.Expression = item;
         this.Start();
         string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
         this.Context.ParameterIndex++;
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
         this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
     }
     else if ((item is MemberExpression) && ((MemberExpression)item).Expression == null)
     {
         var    paramterValue = ExpressionTool.GetPropertyValue(item as MemberExpression);
         string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
         this.Context.ParameterIndex++;
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
         this.Context.Parameters.Add(new SugarParameter(parameterName, paramterValue));
     }
     else if ((item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
     {
         this.Expression = item;
         this.Start();
         string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
         this.Context.ParameterIndex++;
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
         this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
     }
     else if (item is MemberExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             this.Context.Result.CurrentParameter       = parameter;
             this.Context.Result.IsLockCurrentParameter = true;
             parameter.IsAppendTempDate();
             this.Expression = item;
             this.Start();
             parameter.IsAppendResult();
             this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
             this.Context.Result.CurrentParameter = null;
         }
     }
     else if (item is UnaryExpression && ((UnaryExpression)item).Operand is MemberExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             var expression = ((UnaryExpression)item).Operand as MemberExpression;
             if (expression.Expression == null)
             {
                 this.Context.Result.CurrentParameter       = parameter;
                 this.Context.Result.IsLockCurrentParameter = true;
                 parameter.IsAppendTempDate();
                 this.Expression = item;
                 this.Start();
                 parameter.IsAppendResult();
                 this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
                 this.Context.Result.CurrentParameter = null;
             }
             else if (expression.Expression is ConstantExpression)
             {
                 string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
                 this.Context.ParameterIndex++;
                 parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
                 this.Context.Parameters.Add(new SugarParameter(parameterName, ExpressionTool.GetMemberValue(expression.Member, expression)));
             }
             else
             {
                 this.Context.Result.CurrentParameter       = parameter;
                 this.Context.Result.IsLockCurrentParameter = true;
                 parameter.IsAppendTempDate();
                 this.Expression = item;
                 this.Start();
                 parameter.IsAppendResult();
                 this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
                 this.Context.Result.CurrentParameter = null;
             }
         }
     }
     else if (item is UnaryExpression && ((UnaryExpression)item).Operand is ConstantExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             this.Expression = ((UnaryExpression)item).Operand;
             this.Start();
             string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
             this.Context.ParameterIndex++;
             parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
             this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
         }
     }
     else if (item is BinaryExpression)
     {
         if (this.Context.Result.IsLockCurrentParameter == false)
         {
             var newContext         = this.Context.GetCopyContext();
             var resolveExpressType = this.Context.IsSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple;
             newContext.Resolve(item, resolveExpressType);
             this.Context.Index          = newContext.Index;
             this.Context.ParameterIndex = newContext.ParameterIndex;
             if (newContext.Parameters.IsValuable())
             {
                 this.Context.Parameters.AddRange(newContext.Parameters);
             }
             this.Context.Result.Append(this.Context.GetAsString(asName, newContext.Result.GetString()));
             this.Context.Result.CurrentParameter = null;
         }
     }
     else if (item.Type.IsClass())
     {
         this.Expression = item;
         this.Start();
         var shortName      = parameter.CommonTempData;
         var listProperties = item.Type.GetProperties().Cast <PropertyInfo>().ToList();
         foreach (var property in listProperties)
         {
             var hasIgnore = this.Context.IgnoreComumnList != null && this.Context.IgnoreComumnList.Any(it => it.EntityName.Equals(item.Type.Name, StringComparison.CurrentCultureIgnoreCase) && it.PropertyName.Equals(property.Name, StringComparison.CurrentCultureIgnoreCase));
             if (hasIgnore)
             {
                 continue;
             }
             if (property.PropertyType.IsClass())
             {
             }
             else
             {
                 asName = this.Context.GetTranslationText(item.Type.Name + "." + property.Name);
                 var columnName = property.Name;
                 if (Context.IsJoin)
                 {
                     this.Context.Result.Append(Context.GetAsString(asName, columnName, shortName.ObjToString()));
                 }
                 else
                 {
                     this.Context.Result.Append(Context.GetAsString(asName, columnName));
                 }
             }
         }
     }
     else if (item is MethodCallExpression || item is UnaryExpression)
     {
         this.Expression = item;
         this.Start();
         parameter.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
     }
     else
     {
         Check.ThrowNotSupportedException(item.GetType().Name);
     }
 }
コード例 #5
0
        public NewArrayExpessionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var expression = (NewArrayExpression)base.Expression;

            switch (base.Context.ResolveType)
            {
            case ResolveExpressType.WhereSingle:
            case ResolveExpressType.WhereMultiple:
            case ResolveExpressType.SelectSingle:
            case ResolveExpressType.SelectMultiple:
            case ResolveExpressType.FieldSingle:
            case ResolveExpressType.FieldMultiple:
                try
                {
                    var value         = ExpressionTool.DynamicInvoke(expression);
                    var isLeft        = parameter.IsLeft;
                    var baseParameter = parameter.BaseParameter;
                    var isSetTempData = baseParameter.CommonTempData.HasValue() && baseParameter.CommonTempData.Equals(CommonTempDataType.Result);
                    if (isSetTempData)
                    {
                        baseParameter.CommonTempData = value;
                    }
                    else
                    {
                        var parentIsBinary = parameter.BaseParameter.CurrentExpression is BinaryExpression;
                        var parentIsRoot   = parameter.BaseParameter.CurrentExpression is LambdaExpression;
                        var isBool         = value != null && value.GetType() == UtilConstants.BoolType;
                        if (parentIsRoot && isBool)
                        {
                            this.Context.Result.Append(value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False());
                            break;
                        }
                        if (parentIsBinary && isBool)
                        {
                            var isLogicOperator =
                                parameter.BaseExpression.NodeType == ExpressionType.And ||
                                parameter.BaseExpression.NodeType == ExpressionType.AndAlso ||
                                parameter.BaseExpression.NodeType == ExpressionType.Or ||
                                parameter.BaseExpression.NodeType == ExpressionType.OrElse;
                            if (isLogicOperator)
                            {
                                AppendMember(parameter, isLeft, (value.ObjToBool() ? this.Context.DbMehtods.True() : this.Context.DbMehtods.False()));
                                break;
                            }
                        }
                        if (value == null && parentIsBinary)
                        {
                            parameter.BaseParameter.ValueIsNull = true;
                            value = this.Context.DbMehtods.Null();
                        }
                        AppendValue(parameter, isLeft, value);
                    }
                }
                catch (Exception)
                {
                    Check.ThrowNotSupportedException("NewArrayExpression");
                }
                break;

            case ResolveExpressType.ArraySingle:
                foreach (var item in expression.Expressions)
                {
                    base.Expression = item;
                    base.Start();
                }
                break;

            case ResolveExpressType.Join:
                base.Context.ResolveType = ResolveExpressType.WhereMultiple;
                int i = 0;
                foreach (var item in expression.Expressions)
                {
                    if (item is UnaryExpression)
                    {
                        base.Expression = item;
                        base.Start();
                        if (parameter.CommonTempData is JoinType)
                        {
                            if (i > 0)
                            {
                                base.Context.Result.Append("," + parameter.CommonTempData.ObjToString().Replace(",", UtilConstants.ReplaceCommaKey) + ",");
                            }
                            else
                            {
                                base.Context.Result.Append(parameter.CommonTempData.ObjToString().Replace(",", UtilConstants.ReplaceCommaKey) + ",");
                            }
                            ++i;
                        }
                    }
                }
                break;

            default:
                break;
            }
        }
コード例 #6
0
        public NewExpressionResolve(ExpressionParameter parameter) : base(parameter)
        {
            var expression = base.Expression as NewExpression;

            if (expression.Type.IsIn(UtilConstants.DateType, UtilConstants.GuidType))
            {
                NewValueType(parameter, expression);
                return;
            }
            switch (parameter.Context.ResolveType)
            {
            case ResolveExpressType.WhereSingle:
                Check.ThrowNotSupportedException(expression.ToString());
                break;

            case ResolveExpressType.WhereMultiple:
                Check.ThrowNotSupportedException(expression.ToString());
                break;

            case ResolveExpressType.SelectSingle:
                Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
                Select(expression, parameter, true);
                break;

            case ResolveExpressType.SelectMultiple:
                Check.Exception(expression.Type == UtilConstants.DateType, "ThrowNotSupportedException {0} ", expression.ToString());
                Select(expression, parameter, false);
                break;

            case ResolveExpressType.FieldSingle:
                Check.ThrowNotSupportedException(expression.ToString());
                break;

            case ResolveExpressType.FieldMultiple:
            case ResolveExpressType.ArrayMultiple:
            case ResolveExpressType.ArraySingle:
                foreach (var item in expression.Arguments)
                {
                    base.Expression = item;
                    base.Start();
                }
                break;

            case ResolveExpressType.Join:
                base.Context.ResolveType = ResolveExpressType.WhereMultiple;
                int i = 0;
                foreach (var item in expression.Arguments)
                {
                    if (item.Type != typeof(JoinType))
                    {
                        base.Expression = item;
                        base.Start();
                    }
                    if (item.Type == typeof(JoinType))
                    {
                        if (i > 0)
                        {
                            base.Context.Result.Append("," + item.ToString() + ",");
                        }
                        else
                        {
                            base.Context.Result.Append(item.ToString() + ",");
                        }
                        ++i;
                    }
                }
                break;

            default:
                break;
            }
        }
コード例 #7
0
ファイル: CacheService.cs プロジェクト: yshbchenlie/SqlSugar
 public void Add(string key, V value, int cacheDurationInSeconds)
 {
     Check.ThrowNotSupportedException("ReflectionInoCache.Add(string key, V value, int cacheDurationInSeconds)");
 }