public void ValueTypeConditionBuilder() { var filter = new ValueTypeFilter <User, int>(); filter.For(x => x.Id); filter.Conditions(conditions => { conditions["none"] = new ValueTypeNoneCondition <int>(); conditions["equal"] = new ValueTypeEqualCondition <int>(); conditions["isin"] = new ValueTypeIsInCondition <int>(); conditions["isnull"] = new ValueTypeIsNullCondition <int>(); conditions["isnotnull"] = new ValueTypeIsNullCondition <int>(); }); filter.ConditionBuilder((filterValue, condition, conditionKey) => { var expression = condition(filterValue); if (expression == null) { return(null); } switch (conditionKey) { case "isnotnull": { return(Linq.Expr <Task, bool>(x => x.Users.AsQueryable().Any())); } case "isnull": { return(Linq.Expr <Task, bool>(x => !x.Users.AsQueryable().Any())); } default: //for equal,isin { return(Linq.Expr <Task, bool>(x => x.Users.AsQueryable().Any(expression))); } } }); filter.Init(new FilterValue <int?> { LeftValue = 1, ConditionKey = "equal" }); var expr1 = filter.BuildExpression <User>(); Assert.IsNull(expr1); var epxr2 = filter.BuildExpression <Task>(); Assert.IsNotNull(epxr2); var tasksAnyUserId1 = filter.ApplyFilter(Source); Assert.IsTrue(tasksAnyUserId1.Count() == 1); filter.Init(new FilterValue <int?> { ConditionKey = "isnotnull" }); var tasksAnyUsers = filter.ApplyFilter(Source); Assert.IsTrue(tasksAnyUsers.Count() == 3); filter.Init(new FilterValue <int?> { ConditionKey = "isnull" }); var tasksNotAnyUsers = filter.ApplyFilter(Source); Assert.IsTrue(tasksNotAnyUsers.Count() == 1); filter.Init(new FilterValue <int?> { ConditionKey = "isin", Values = new List <int?> { 1, 5 } }); var tasksIsInUser1User5 = filter.ApplyFilter(Source); Assert.IsTrue(tasksIsInUser1User5.Count() == 2); }