Given this code:
int min = 0;
Expression<Func<List<IUser>, bool>> ulContainsJohn =
(l => l.Where(u => u.FirstName == "John").Count() > min);
Assert.AreEqual(true, ulContainsJohn.Compile()(userList));
min = 3;
Assert.AreEqual(true, ulContainsJohn.Compile()(userList));
The list contains 1 "John", yet the second assert fails. How do I bind the value of min to the Func eagerly, so it doesn't try to re-evaluate the variable min?
Clarification: I don't want to change the signature. I want the expression tree to avaluate min not as a variable, but as a constant expression. Is there anyway to convert the evaluation of min so that the tree has a constant expression instead of a variable evaluation?