Exemplo n.º 1
0
        public void TestFilterConvention()
        {
            Expression <Func <Author, Boolean> > expression = (a) => a.Name.StartsWith("a");
            var func = expression.Compile();

            Assert.IsTrue(func.Invoke(new Author(1, "araf")));
            Assert.IsFalse(func.Invoke(new Author(1, "dff")));

            var filterExpr = ConventionBuilder <Author> .FilterExpression(new AuthorDto { Name = "a" });

            func = filterExpr.Compile();
            Assert.IsTrue(func.Invoke(new Author(1, "araf")));
            Assert.IsFalse(func.Invoke(new Author(1, "dff")));

            filterExpr = ConventionBuilder <Author> .FilterExpression(new BookOrAuthorQriteria { Name = "a" });

            func = filterExpr.Compile();
            Assert.IsTrue(func.Invoke(new Author(1, "araf")));
            Assert.IsFalse(func.Invoke(new Author(1, "dff")));

            //AuthorDto author = new AuthorDto { Name = "a" };
            //var result = Conventions<Author>.FilterExpression(author);

            //Assert.AreEqual(2, Authors.Where(result).First().Id);
        }
Exemplo n.º 2
0
        public IQueryable Query(ILinqProvider linqProvider, IPageQriteria <TParam> qrit)
        {
            var filterExpr = qrit.Subject != null ?
                             ConventionBuilder <TEntity> .FilterExpression(qrit.Subject)
                                : (x) => true;

            var query = linqProvider
                        .Query <TEntity>()
                        .Where(filterExpr)
                        .OrderByConventions(qrit);

            return(query);
        }
Exemplo n.º 3
0
 public IQueryable <TEntity> Query(IQueryable <TEntity> query, TParam qrit)
 => query.Where(ConventionBuilder <TEntity> .FilterExpression(qrit));