static void Main(string[] args) { var list = new Person[] { new Person() { Name = "code6421", Age = 12 }, new Person() { Name = "mary", Age = 16 }, new Person() { Name = "ark", Age = 12 }, new Person() { Name = "jerry", Age = 14 }, }; var expr = ExpressionHelper <Person> .Create(a => a.Name == "code6421"); expr = ExpressionHelper <Person> .And(expr, a => a.Age == 12); foreach (var item in list.AsQueryable().Where(expr)) { Console.WriteLine(item.Name); } Console.ReadLine(); }
public Expression <Func <PostLike, bool> > GetExpressionToFilter(PostLikeQuery query) { Expression <Func <PostLike, bool> > expression = null; if (query.PostId.HasValue) { expression = x => x.PostId == query.PostId; } if (!string.IsNullOrEmpty(query.IpAddress)) { expression = ExpressionHelper.And <PostLike>(expression, x => x.IPAddress == query.IpAddress); } return(expression); }
public QueryEngine.Expressions.Expression Expression() { Expression[] _expressions = new Expression[DBFilters.Count]; for (int i = 0; i < DBFilters.Count; i++) { _expressions[i] = DBFilters[i].Expression(); } switch (LogicalOperator) { case DBLogicalOperator.And: return(ExpressionHelper.And(_expressions)); default: case DBLogicalOperator.Or: return(ExpressionHelper.Or(_expressions)); } }