private static Expression <Func <T, object> > BuildSort(Sort sort) { return((Expression <Func <T, object> >)CriterionHelper.BuildSortExpression(typeof(T), sort.Field)); }
private static Expression <Func <T, bool> > BuildPredicate(Filter[] filters) { return((Expression <Func <T, bool> >)CriterionHelper.BuildPredicate(typeof(T), filters)); }
private static Expression <Func <T, bool> > BuildSameIdentitiesPredicate(object @object) { return((Expression <Func <T, bool> >)CriterionHelper.BuildSameIdentitiesPredicate(typeof(T), @object)); }
private Func <T, bool> BuildCriterion(Condition[] filters) { return(CriterionHelper.BuildPredicate <T>(filters).Compile()); }
public void BuildCriterionTestWithOperators() { var where = CriterionHelper.BuildPredicate <Party>(new[] { new Condition { Path = "Gln", Value = "glnValue", Operator = ObjectFieldFilterOperator.Equals }, new Condition { Path = "Id", Value = "10", Operator = ObjectFieldFilterOperator.LessThan }, new Condition { Path = "Address.City", Value = "cityValue", Operator = ObjectFieldFilterOperator.Equals } }); var sort1 = CriterionHelper.BuildSort <Party, int>(new Sort { Path = "Id", SortOrder = ObjectFilterSortOrder.Ascending }); var sort2 = CriterionHelper.BuildSort <Party, string>(new Sort { Path = "Address.City", SortOrder = ObjectFilterSortOrder.Ascending }); var entries = new[] { new Party { Gln = "213", Id = 10, Address = new Address { City = "abc" } }, new Party { Gln = "glnValue", Id = 9, Address = new Address { City = "cityValue" } }, new Party { Gln = "glnValue", Id = 10, Address = new Address { City = "cityValue" } }, new Party { Gln = "215", Id = 11, Address = new Address { City = "cbc" } }, new Party { Gln = "glnValue", Id = 8, Address = new Address { City = "cityValue" } }, new Party { Gln = "qwret", Id = 6, Address = new Address { City = "cityValue" } }, new Party { Gln = "glnValue", Id = 7, Address = new Address { City = "zbx" } }, new Party { Gln = "215", Id = 8, Address = new Address { City = "qwc" } }, }; var query = entries.AsQueryable().Where(where).OrderBy(sort1).ThenBy(sort2).ToArray(); query.Should().BeEquivalentTo(entries.Where(x => x.Gln == "glnValue" && x.Id < 10 && x.Address.City == "cityValue").OrderBy(x => x.Id).ThenBy(x => x.Address), x => x.WithStrictOrdering()); var query2 = entries.AsQueryable().OrderBy(sort1).ThenBy(sort2).ToArray(); query2.Should().BeEquivalentTo(entries.OrderBy(x => x.Id).ThenBy(x => x.Address.City), x => x.WithStrictOrdering()); }
private static IQueryable <T> BuildQuery(IQueryable <T> query, Condition[] filters) { return(filters.Any() ? query.Where(CriterionHelper.BuildPredicate <T>(filters)) : query); }
private static IOrderedQueryable <T> AddSort <TProperty>(IOrderedQueryable <T> query, Sort sort) { return(sort.SortOrder == ObjectFilterSortOrder.Ascending ? query.ThenBy(CriterionHelper.BuildSort <T, TProperty>(sort)) : query.ThenByDescending(CriterionHelper.BuildSort <T, TProperty>(sort))); }