コード例 #1
0
        public int Count <T>(IDbConnection connection, Expression <Func <T, bool> > expression, IDbTransaction transaction, int?commandTimeout) where T : class
        {
            IClassMapper classMap       = SqlGenerator.Configuration.GetMap <T>();
            IPredicate   wherePredicate = ExpressionPredicateConvert.GetExpressionPredicate(expression);

            return(Count <T>(connection, classMap, wherePredicate, transaction, commandTimeout));
        }
コード例 #2
0
        public IEnumerable <T> GetPage <T>(IDbConnection connection, Expression <Func <T, bool> > expression, IList <ISort> sort, int page, int resultsPerPage, IDbTransaction transaction, int?commandTimeout, bool buffered) where T : class
        {
            IClassMapper classMap       = SqlGenerator.Configuration.GetMap <T>();
            IPredicate   wherePredicate = ExpressionPredicateConvert.GetExpressionPredicate(expression);

            return(GetPage <T>(connection, classMap, wherePredicate, sort, page, resultsPerPage, transaction, commandTimeout, buffered));
        }
コード例 #3
0
        public void TestGroup()
        {
            IPredicate            p = ExpressionPredicateConvert.GetExpressionPredicate <User>(u => u.Id == 1 || (u.Id == 2 && u.Name.Contains("1")));
            FieldPredicate <User> f = (p as IPredicateGroup).Predicates[0] as FieldPredicate <User>;

            Assert.True(System.Convert.ToInt32(f.Value) == 1);
            Assert.True((p as IPredicateGroup).Operator == GroupOperator.Or);
            Expression <Func <User, bool> > expr = u => u.Id == 1 || (u.Id == 2 && u.Name.Contains("1"));
        }
コード例 #4
0
        public void TestBase()
        {
            IPredicate            p1 = ExpressionPredicateConvert.GetExpressionPredicate <User>(u => u.Id != 1);
            FieldPredicate <User> f1 = p1 as FieldPredicate <User>;

            Assert.True(f1.Operator == Operator.Eq);
            Assert.True(f1.Not);

            IPredicate            pGe = ExpressionPredicateConvert.GetExpressionPredicate <User>(u => u.Id >= 1);
            FieldPredicate <User> fGe = pGe as FieldPredicate <User>;

            Assert.True(fGe.Operator == Operator.Ge);
        }
コード例 #5
0
        public void TestIn()
        {
            List <string> valueList = new List <string>()
            {
                "1", "2", "3"
            };
            IPredicate            p = ExpressionPredicateConvert.GetExpressionPredicate <User>(u => valueList.Contains(u.Name));
            FieldPredicate <User> f = p as FieldPredicate <User>;

            Assert.True(f.Operator == Operator.Eq);
            Assert.True((f.Value as List <string>).Count == 3);

            IPredicate            p2 = ExpressionPredicateConvert.GetExpressionPredicate <User>(u => !valueList.Contains(u.Name));
            FieldPredicate <User> f2 = p2 as FieldPredicate <User>;

            Assert.True(f.Not == true);
        }
コード例 #6
0
        public void TestLike()
        {
            IPredicate            p1 = ExpressionPredicateConvert.GetExpressionPredicate <User>(u => u.Name.Contains("1"));
            FieldPredicate <User> f1 = p1 as FieldPredicate <User>;

            Assert.True(f1.Operator == Operator.Like);
            Assert.True(f1.Value.ToString() == "%1%");

            IPredicate            p2 = ExpressionPredicateConvert.GetExpressionPredicate <User>(u => u.Name.StartsWith("1"));
            FieldPredicate <User> f2 = p2 as FieldPredicate <User>;

            Assert.True(f2.Operator == Operator.Like);
            Assert.True(f2.Value.ToString() == "1%");

            IPredicate            p3 = ExpressionPredicateConvert.GetExpressionPredicate <User>(u => u.Name.EndsWith("1"));
            FieldPredicate <User> f3 = p3 as FieldPredicate <User>;

            Assert.True(f3.Operator == Operator.Like);
            Assert.True(f3.Value.ToString() == "%1");
        }