예제 #1
0
        /// <summary>
        /// 与逻辑运算
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="expLeft">表达式1</param>
        /// <param name="propertyName">属性名称</param>
        /// <param name="value">属性值</param>
        /// <param name="operator">操作符</param>
        /// <exception cref="MissingFieldException"></exception>
        /// <exception cref="NotSupportedException"></exception>
        /// <returns></returns>
        public static Expression <Func <T, bool> > And <T>(this Expression <Func <T, bool> > expLeft,
                                                           string propertyName, object value, SQLOperator @operator)
        {
            var expRight = SQLPredicate.Create <T>(propertyName, value, @operator);

            return(expLeft.And(expRight));
        }
예제 #2
0
        /// <summary>
        /// 转换为Or连接的谓词筛选表达式
        /// </summary>
        /// <param name="falseWhenNull">当生成的表达式为null时返回false表达式</param>
        /// <returns></returns>
        public Expression <Func <T, bool> > ToOrPredicate(bool falseWhenNull = true)
        {
            if (Items.Count == 0)
            {
                return(falseWhenNull ? SQLPredicate.False <T>() : null);
            }

            return(Items
                   .Select(item => item.ToPredicate())
                   .Aggregate((left, right) => left.Or(right)));
        }
예제 #3
0
        /// <summary>
        /// 与逻辑运算
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <typeparam name="TKey">属性类型</typeparam>
        /// <param name="expLeft">表达式1</param>
        /// <param name="keySelector">属性选择</param>
        /// <param name="value">值</param>
        /// <param name="operator">操作符</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="NotSupportedException"></exception>
        /// <returns></returns>
        public static Expression <Func <T, bool> > And <T, TKey>(this Expression <Func <T, bool> > expLeft,
                                                                 Expression <Func <T, TKey> > keySelector, TKey value, SQLOperator @operator)
        {
            if (keySelector is null)
            {
                throw new ArgumentNullException(nameof(keySelector));
            }
            var expRight = SQLPredicate.Create(keySelector, value, @operator);

            return(expLeft.And(expRight));
        }
예제 #4
0
        /// <summary>
        /// 与逻辑运算
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <typeparam name="TKey">属性类型</typeparam>
        /// <param name="expLeft">表达式1</param>
        /// <param name="keySelector">属性选择</param>
        /// <param name="values">值</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <returns></returns>
        public static Expression <Func <T, bool> > AndNotIn <T, TKey>(this Expression <Func <T, bool> > expLeft,
                                                                      Expression <Func <T, TKey> > keySelector, IEnumerable <TKey> values)
        {
            if (keySelector is null)
            {
                throw new ArgumentNullException(nameof(keySelector));
            }

            // ReSharper disable once PossibleMultipleEnumeration
            if (values is null || values.Any() == false)
            {
                return(expLeft);
            }

            // ReSharper disable once PossibleMultipleEnumeration
            var expRight = SQLPredicate.CreateAndNotEqual(keySelector, values);

            return(expLeft.And(expRight));
        }
예제 #5
0
 /// <summary>
 /// 转换为谓词筛选表达式
 /// </summary>
 /// <exception cref="NotSupportedException"></exception>
 /// <returns></returns>
 public Expression <Func <T, bool> > ToPredicate() => SQLPredicate.Create <T>(Member, Value, Operator);