Beispiel #1
0
 /// <summary>
 /// Combines the first predicate with the second using a logical "or". Short-circuits if either expression is constant
 /// </summary>
 /// <typeparam name="T">The input type for both predicates</typeparam>
 /// <param name="first">The first predicate</param>
 /// <param name="second">The second predicate</param>
 /// <returns>An expression representing a logical "or" between both predicates</returns>
 public static Expression <Func <T, bool> > Or <T>(this Expression <Func <T, bool> > first,
                                                   Expression <Func <T, bool> > second)
 {
     if (ExpressionUtility.IsConstant(first, false))
     {
         return(second);
     }
     if (ExpressionUtility.IsConstant(second, false))
     {
         return(first);
     }
     if (ExpressionUtility.IsConstant(first, true) || ExpressionUtility.IsConstant(second, true))
     {
         return(True <T>());
     }
     return(first.Combine(second, (a, b) => a || b));
 }
        /// <summary>
        /// 查询条件表达式转换为谓词组的扩展方法
        /// </summary>
        /// <typeparam name="TEntity">实体类型</typeparam>
        /// <typeparam name="TPrimaryKey">实体主键类型</typeparam>
        /// <param name="expression">查询条件表达式</param>
        /// <returns>查询条件谓词组</returns>
        public static IPredicate ToPredicateGroup <TEntity, TPrimaryKey>(
            this Expression <Func <TEntity, bool> > expression) where TEntity : class
        {
            if (expression == null)
            {
                return(null);
            }

            if (ExpressionUtility.IsConstant(expression, true))
            {
                return(null);
            }

            if (ExpressionUtility.IsConstant(expression, false))
            {
                return(null);
            }

            IPredicate pg = QueryBuilder <TEntity> .FromExpression(expression);

            return(pg);
        }