예제 #1
0
        /// <summary>
        /// 对静态方法或实例方法的调用
        /// </summary>
        /// <param name="exp"></param>
        /// <param name="isNotOprand"></param>
        /// <returns></returns>
        private QueryParameter MethodCallExpressionProvider(Expression exp, bool isNotOprand = false)
        {
            QueryParameter       qp              = null;
            object               name            = null;
            object               value           = null;
            DbType               parameterDbType = DbType.Object;
            Operand              op              = Operand.Equal;
            MethodCallExpression mce             = exp as MethodCallExpression;

            switch (mce.Method.Name)
            {
            case "Equals":
                name            = MemberExpressionProvider(mce.Object);
                value           = Expression.Lambda(mce.Arguments[0]).Compile().DynamicInvoke().ToString();
                op              = isNotOprand ? Operand.NotEqual : Operand.Equal;
                parameterDbType = DbTypeConvertor.GetDbType(value);
                break;

            case "Contains":
                if (mce.Object != null)
                {
                    if (mce.Object is MemberExpression && ((MemberExpression)mce.Object).Member.MemberType == MemberTypes.Property)
                    {       // task.Name.Contains("T1"); task.Name.Contains(keywords);
                        name            = AtomExpressionRouter(mce.Object);
                        value           = AtomExpressionRouter(mce.Arguments[0]);
                        op              = isNotOprand ? Operand.NotLike : Operand.Like;
                        parameterDbType = DbTypeConvertor.GetDbType(value);
                    }
                    else
                    {       //permIds.Contains(a.Id)
                        name            = AtomExpressionRouter(mce.Arguments[0]);
                        value           = AtomExpressionRouter(mce.Object);
                        parameterDbType = DbTypeConvertor.TypeToDbType(mce.Arguments[0].Type);
                        op = isNotOprand ? Operand.NotIn : Operand.In;
                    }
                }
                else if (mce.Arguments.Count >= 2)
                {       //int与int?类型 list:List<int?>
                    name            = AtomExpressionRouter(mce.Arguments[1]);
                    value           = AtomExpressionRouter(mce.Arguments[0]);
                    parameterDbType = DbTypeConvertor.TypeToDbType(mce.Arguments[1].Type);
                    op = isNotOprand ? Operand.NotIn : Operand.In;
                }
                else
                {
                    throw new Exception($"不支持的方法:{mce.ToString()}");
                }
                break;

            case "StartsWith":
                name = MemberExpressionProvider(mce.Object);
                //value = ConstantExpressionProvider(mce.Arguments[0]);
                value           = Expression.Lambda(mce.Arguments[0]).Compile().DynamicInvoke().ToString();
                op              = Operand.LeftLike;
                parameterDbType = DbTypeConvertor.GetDbType(value);
                break;

            case "EndsWith":
                name = MemberExpressionProvider(mce.Object);
                //value = ConstantExpressionProvider(mce.Arguments[0]);
                value           = Expression.Lambda(mce.Arguments[0]).Compile().DynamicInvoke().ToString();
                op              = Operand.RightLike;
                parameterDbType = DbTypeConvertor.GetDbType(value);
                break;

            default:
                throw new Exception("不支持的方法:" + mce.Method.Name);
            }
            qp = new QueryParameter()
            {
                FieldName       = name?.ToString(),
                Op              = op,
                ParameterValue  = value,
                ParameterDbType = parameterDbType
            };
            return(qp);
        }
예제 #2
0
파일: PiMap.cs 프로젝트: 279328316/JcCore
 /// <summary>
 /// Ctor
 /// </summary>
 public PiMap(PropertyInfo pi, FieldAttribute fieldAttr)
 {
     this.pi        = pi;
     this.fieldAttr = fieldAttr;
     this.dbType    = DbTypeConvertor.TypeToDbType(pi.PropertyType);
 }
예제 #3
0
 /// <summary>
 /// 增加查询项
 /// </summary>
 /// <param name="fieldName"></param>
 /// <param name="conjuction"></param>
 /// <param name="operand"></param>
 /// <param name="compareValue"></param>
 /// <returns></returns>
 public virtual void AddQueryItem(string fieldName, Conjuction conjuction, Operand operand, object compareValue)
 {
     AddQueryItem(fieldName, conjuction, operand, compareValue, DbTypeConvertor.GetDbType(compareValue));
 }