Beispiel #1
0
        /// <summary>
        /// 操作
        /// </summary>
        /// <param name="left">左操作数</param>
        /// <param name="operator">运算符</param>
        /// <param name="value">值</param>
        public static Expression Operation(this Expression left, OperatorLmada @operator, object value)
        {
            switch (@operator)
            {
            case OperatorLmada.Equal:
                return(left.Equal(value));

            case OperatorLmada.NotEqual:
                return(left.NotEqual(value));

            case OperatorLmada.Greater:
                return(left.Greater(value));

            case OperatorLmada.GreaterEqual:
                return(left.GreaterEqual(value));

            case OperatorLmada.Less:
                return(left.Less(value));

            case OperatorLmada.LessEqual:
                return(left.LessEqual(value));

            case OperatorLmada.Starts:
                return(left.StartsWith(value));

            case OperatorLmada.Ends:
                return(left.EndsWith(value));

            case OperatorLmada.Contains:
                return(left.Contains(value));
            }
            throw new NotImplementedException();
        }
 /// <summary>
 /// 添加表达式
 /// </summary>
 /// <param name="property">属性名</param>
 /// <param name="operator">运算符</param>
 /// <param name="value">值</param>
 public void Append(string property, OperatorLmada @operator, object value)
 {
     _result = _result.And(_parameter.Property(property).Operation(@operator, value));
 }
 /// <summary>
 /// 添加表达式
 /// </summary>
 /// <typeparam name="TProperty">属性类型</typeparam>
 /// <param name="propertyExpression">属性表达式</param>
 /// <param name="operator">运算符</param>
 /// <param name="value">值</param>
 public void Append <TProperty>(Expression <Func <TEntity, TProperty> > propertyExpression, OperatorLmada @operator,
                                object value)
 {
     _result = _result.And(_parameter.Property(LambdaHelper.GetMember(propertyExpression))
                           .Operation(@operator, value));
 }
Beispiel #4
0
        /// <summary>
        /// 解析为谓词表达式
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="propertyName">属性名</param>
        /// <param name="value">值</param>
        /// <param name="operator">运算符</param>
        /// <returns></returns>
        public static Expression <Func <T, bool> > ParsePredicate <T>(string propertyName, object value, OperatorLmada @operator)
        {
            var parameter = Expression.Parameter(typeof(T), "t");

            return(parameter
                   .Property(propertyName)
                   .Operation(@operator, value)
                   .ToLambda <Func <T, bool> >(parameter));
        }